您的位置:首页 > 其它

leetcode 104: Maximum Depth of Binary Tree

2015-08-12 13:06 405 查看
/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int maxDepth(TreeNode* root) {
return helper(root,1);
}
int helper(TreeNode* root,int depth)
{
if(!root)
return depth-1;
return max(helper(root->left,depth+1),helper(root->right,depth+1));
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: