1
class Solution {
2
int ans = Integer.MAX_VALUE;
3
boolean x = true;
4

5
public int findSecondMinimumValue(TreeNode root) {
6
go(root);
7
return x ? -1 : ans;
8
}
9

10
private void go(TreeNode root) {
11
if (root == null) return;
12
if (root.left != null) {
13
if (root.left.val == root.val) go(root.left);
14
else {
15
x = false;
16
ans = Math.min(ans, root.left.val);
17
}
18
}
19
if (root.right != null) {
20
if (root.right.val == root.val) go(root.right);
21
else {
22
x = false;
23
ans = Math.min(ans, root.right.val);
24
}
25
}
26
}
27
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0