JZ55 二叉树的深度

public class Solution {
    public int TreeDepth(TreeNode root) {
        //空节点没有深度
        if(root == null)
            return 0;
        //返回子树深度+1
        return Math.max(TreeDepth(root.left), TreeDepth(root.right)) + 1;
    }
}

好简单啊

posted on 2022-06-27 14:54  MaXianZhe  阅读(6)  评论(0编辑  收藏  举报

导航