首页 > 代码库 > 【LeetCode】 Maximum Depth of Binary Tree

【LeetCode】 Maximum Depth of Binary Tree

Maximum Depth of Binary Tree 

Given a binary tree, find its maximum depth.

The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

 

递归基础,不解释。

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