解题思路:
(1)dfs
class Solution {
private:
int max_h=0;
public:
void helper(TreeNode *root,int h) {
if(!root) return;
helper(root->left,h+1);
if(max_h<h) max_h=h;
helper(root->right,h+1);
return;
}
int maxDepth(TreeNode* root) {
if(root==nullptr) return 0;
helper(root,0);
return max_h+1;
}
};