0%

LeetCode-104

题目

结果

代码

1
2
3
4
5
6
7
8
class Solution {
public int maxDepth(TreeNode root) {
if (root == null) {
return 0;
}
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
}
}

复杂度

时间复杂度:O(n)

空间复杂度:O(n)