Maximum Depth of Binary Tree Java

原创 2015年07月08日 11:40:36

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.

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public int maxDepth(TreeNode root) {
        if(root==null){
            return 0;
        }
        int left = maxDepth(root.left);
        int right = maxDepth(root.right);
        return Math.max(left,right)+1;
    }
}


leetcode解题之Maximum/Minimum Depth of Binary Tree Java版(树的最大、最小深度)

leetcode解题之104# Maximum Depth of Binary Tree Java版(树的最大深度),111. Minimum Depth of Binary Tree(树的最大深度...

Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 [java]

Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the short...

No104. Maximum Depth of Binary Tree

一、题目描述 Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along t...

Leetcode-104. Maximum Depth of Binary Tree c语言

来源:104. Maximum Depth of Binary Tree 题目要求: Given a binary tree, find its maximum depth. The max...
  • tzh476
  • tzh476
  • 2016年07月03日 19:06
  • 551

LeetCode104 Maximum Depth of Binary Tree

详细见:leetcode.com/problems/maximum-depth-of-binary-tree Java Solution: github package leetcod...
  • zxwtry
  • zxwtry
  • 2017年04月27日 22:00
  • 234

Maximum Depth of Binary Tree

Problem:Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along...

开荒新系列之LeetCode: 002-Maximum Depth of Binary Tree

总结讨论在不看上一篇文章的前提下,回忆总结一下上次工作,看看到目前为止还记得多少: 要多手写一些测试数据 不止一种方法实现,寻找最简单的方法 python is 比 == 要快一点点 Maximum ...

Maximum Depth of Binary Tree --- 求二叉树的最大深度

LeetCode练习题

LeetCode | Maximum Depth of Binary Tree

Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the l...

[LeetCode]104.Maximum Depth of Binary Tree

【题目】 Maximum Depth of Binary Tree  Total Accepted: 5260 Total Submissions: 11532My Submissions ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Maximum Depth of Binary Tree Java
举报原因:
原因补充:

(最多只允许输入30个字)