美文网首页
104. Maximum Depth of Binary Tre

104. Maximum Depth of Binary Tre

作者: juexin | 来源:发表于2017-01-07 14:01 被阅读0次

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.

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

相关文章

网友评论

      本文标题:104. Maximum Depth of Binary Tre

      本文链接:https://www.haomeiwen.com/subject/cydfbttx.html