二叉树的深度

来源:互联网 发布:spss mac下载官网 编辑:程序博客网 时间:2024/05/22 17:32
/*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;                    int left  = TreeDepth(pRoot->left);           int right = TreeDepth(pRoot->right);           return left > right ? ( left + 1 ) : ( right + 1 );    }};

0 0