1
class Solution {
2
public:
3
int findSecondMinimumValue(TreeNode *root) {
4
queue<TreeNode *> q;
5
q.push(root);
6
vector<int> v;
7
while (!q.empty()) {
8
v.push_back(q.front()->val);
9
if (q.front()->left) {
10
q.push(q.front()->left);
11
}
12
if (q.front()->right) {
13
q.push(q.front()->right);
14
}
15
q.pop();
16
}
17
sort(v.begin(), v.end());
18
int ans = -1;
19
for (int i = 1; i < v.size(); i++) {
20
if (v[i] != v[0]) {
21
return v[i];
22
}
23
}
24
return ans;
25
}
26
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0