-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSolution513.java
More file actions
40 lines (34 loc) · 757 Bytes
/
Copy pathSolution513.java
File metadata and controls
40 lines (34 loc) · 757 Bytes
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
38
39
40
package algorithm.leetcode;
/**
* @author: mayuan
* @desc: 找树左下角的值
* @date: 2019/03/15
*/
public class Solution513 {
int ans = 0;
int curDepth = 0;
public int findBottomLeftValue(TreeNode root) {
dfs(root, 1);
return ans;
}
public void dfs(TreeNode node, int depth) {
if (curDepth < depth) {
ans = node.val;
curDepth = depth;
}
if (null != node.left) {
dfs(node.left, depth + 1);
}
if (null != node.right) {
dfs(node.right, depth + 1);
}
}
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) {
val = x;
}
}
}