leetcode-104. Maximum depth of binary tree

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

answer:

Binary tree traversal recursion

  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);

        }

    }

Guess you like

Origin blog.csdn.net/wuqiqi1992/article/details/108326672