Submission Detail

39 / 39 test cases passed.
Status:

Accepted

Runtime: 0 ms
Memory Usage: 41.2 MB
Submitted: 0 minutes ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

0.0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
75
80
85
90
95
100
105
java
Runtime (ms)
Distribution (%)

0
1
2
3
4
5
6
7
8
9
10
80
90
100
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

40800
41000
41200
41400
41600
41800
42000
42200
42400
42600
42800
2
4
6
8
java
You are here!
Your memory usage beats 97.68 % of java submissions.
Memory (KB)
Distribution (%)

40750
41000
41250
41500
41750
42000
42250
42500
42750
5
Zoom area by dragging across this chart

Invite friends to challenge Maximum Depth of Binary Tree


Submitted Code: 0 minutes ago

Language: java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public int maxDepth(TreeNode root) {
// base case
if (root == null)
return 0;
int depth = 1;
// recurse on left/right subtrees
int left = maxDepth(root.left);
int right = maxDepth(root.right);
// increment depth by whichever is greater
if (left > right)
depth += left;
else
depth += right;
return depth;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX