Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 465 Bytes

104. Maximum Depth of Binary Tree.md

File metadata and controls

25 lines (17 loc) · 465 Bytes

104. Maximum Depth of Binary Tree

Problem

Given a binary tree, find its maximum depth.

The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

tag:

Solution

最大树高=左右子树种较高的一个+1

java

    public int maxDepth(TreeNode root) {
        if(root==null) return 0;
        return Math.max(maxDepth(root.left), maxDepth(root.right))+1;
    }

go