递归求二叉树的深度

来源:互联网 发布:hpv报告单怎么看数据 编辑:程序博客网 时间:2024/06/05 04:30
int maxDepth(TreeNode* root) {        if(!root){            return 0;        }        int ldep=maxDepth(root->left);        int rdep=maxDepth(root->right);        return ldep>rdep?ldep+1:rdep+1;    }
如果空结点返回0,否则返回左右子树较深的深度加1(加上根节点)
0 0
原创粉丝点击