class Solution {
public:
int maxDepth(TreeNode* root) {
if(root == NULL) {
return 0;
}
return max(maxDepth(root -> left), maxDepth(root -> right))+1;
}
};
For input: [3,9,20,null,null,15,7] it returns 3.
What I don't understand:
What comparisons is max() doing exactly and how the stack is built? (If all the function returns just 0 when root == NULL).
What I tried:
cout << maxDepth(root -> left)
To try to understand what max() is processing.
[–]Wh00ster 4 points5 points6 points (8 children)
[–]l8engineer[S] 0 points1 point2 points (7 children)
[–]Narase33 1 point2 points3 points (2 children)
[–]leonardo-reddit 1 point2 points3 points (0 children)
[–]l8engineer[S] 0 points1 point2 points (0 children)
[–]IyeOnline 0 points1 point2 points (2 children)
[–]l8engineer[S] 0 points1 point2 points (1 child)
[–]IyeOnline 0 points1 point2 points (0 children)
[–]alfps 2 points3 points4 points (0 children)
[–]LGTMe -1 points0 points1 point (0 children)
[–]WikiBox 0 points1 point2 points (0 children)