0
点赞
收藏
分享

微信扫一扫

二叉树-树的高度

奔跑的酆 2022-02-11 阅读 52
class Solution {
public:
    int TreeDepth(TreeNode* pRoot) {
        if(!pRoot) return 0;
        int iLeftNodes=0;
        int iRightNodes=0;
        if(pRoot->left)
        {
            iLeftNodes=TreeDepth(pRoot->left);
        }

        if(pRoot->right)
        {
            iRightNodes=TreeDepth(pRoot->right);
        }
        return iLeftNodes>iRightNodes?1+iLeftNodes:1+iRightNodes;
    }
};
举报

相关推荐

0 条评论