Maximum Depth of Binary Tree

 

 利用深度优先搜索,递归+1

class Solution {
public:
    int maxDepth(TreeNode* root) 
    {
        if(root==NULL)
        {
            return 0;
        }
        return max(maxDepth(root->left),maxDepth(root->right))+1;
    }
};

  

posted @ 2021-04-01 16:23  章大佬  阅读(18)  评论(0)    收藏  举报