public int maxDepth(TreeNode root) { // 后序遍历 if (root == null){ return 0; } // 此树的深度等于左子树的深度与右子树的深度中的最大值 +1 return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1; }
剑指Offer-56二叉树的深度
最新推荐文章于 2021-04-25 11:37:13 发布
public int maxDepth(TreeNode root) { // 后序遍历 if (root == null){ return 0; } // 此树的深度等于左子树的深度与右子树的深度中的最大值 +1 return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1; }