104

題目:
https://leetcode.com/problems/maximum-depth-of-binary-tree/description/

1
2
3
4
5
6
7
8
class Solution {
public:
int maxDepth(TreeNode* root) {
return root == nullptr ? 0 : max(maxDepth(root->left), maxDepth(root->right)) + 1;
// if root is empty, return 0
// else return the bigger subtree(left or right), then plus 1 (myself)
}
};