/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};*/
class Solution {
public:
int TreeDepth(TreeNode* pRoot)
{
if(pRoot==NULL)
{
return 0;
}
else if(pRoot->left==NULL&&pRoot->right==NULL)
{
return 1;
}else{
int left=TreeDepth(pRoot->left);
int right=TreeDepth(pRoot->right);
if(left>=right)
{
return left+1;
}
else{
return right+1;
}
}
}
};
递归 理解 函数模型变小 递归出口条件
剑指offer 二叉树的深度
最新推荐文章于 2019-10-20 15:30:16 发布