Find Bottom Left Tree Value LeetCode solution in Java

1
class Solution {
2
int max = Integer.MIN_VALUE;
3
int res = -1;
4

5
public int findBottomLeftValue(TreeNode root) {
6
check(root, 0);
7
return res;
8
}
9

10
void check(TreeNode root, int h) {
11
if (root == null) return;
12
if (h > max) {
13
max = h;
14
res = root.val;
15
}
16
check(root.left, h + 1);
17
check(root.right, h + 1);
18
}
19
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0