剑指Offer-56二叉树的深度

public int maxDepth(TreeNode root) {
    // 后序遍历
    if (root == null){
        return 0;
    }
    // 此树的深度等于左子树的深度与右子树的深度中的最大值 +1
    return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
}

猜你喜欢

转载自blog.csdn.net/a792396951/article/details/114259541