二叉树的深度
C++,树深度,递归。
/*
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) return 0;
else
return max(TreeDepth(pRoot->left), TreeDepth(pRoot->right)) + 1;
}
};