leetcode-104.二叉树最大深度

题目:https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/submissions/

答案:

二叉树遍历递归

  public int maxDepth(TreeNode root) {

  if(root==null) {

            return 0;

        }else {

            int heightLeft = 1+maxDepth(root.left);

            int heightRight = 1+maxDepth(root.right);

            return Math.max(heightLeft,heightRight);

        }

    }

猜你喜欢

转载自blog.csdn.net/wuqiqi1992/article/details/108326672
今日推荐