# Maximum Depth of Binary Tree Java

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...

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

• tzh476
• 2016年07月03日 19:06
• 551

## LeetCode104 Maximum Depth of Binary Tree

• 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练习题

## 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个字)