Grokking Microsoft Coding Interview
Vote
0% completed
Hidden Document
Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content
.....
.....
.....
Like the course? Get enrolled and start learning!
L
lejafilip
· 2 years ago
static bool hasPath(TreeNode *root, int sum) { if(!root) return false; std::stack<std::pair<TreeNode*, int>> nodes; nodes.push({root, sum - root->val}); while(!nodes.empty()) { auto node = nodes.top(); nodes.pop(); if(node.second == 0 && !node.first->left && !node.first->right) { return true; } if(node.first->left) nodes.push({node.first->left, node.second - node.first->left->val}); if(node.first->right) nodes.push({node.first->right, node.second - node.first->right->val}); } return false; }
N
Nafis Molla
· 4 years ago
how does the or work in the return statement? Are they both run simultaneously?
Show 3 replies
Reading Progress
0%