LeetCode 104 - Maximum Depth of Binary Tree - 题解/Solution

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* 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.
*
* @author dongyuxi
*
*/
public class Solution {
public int maxDepth(TreeNode root) {
if (null == root) {
return 0;
}

return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
}
}


支付宝 微信
文章目录