-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path671.cpp
36 lines (36 loc) · 849 Bytes
/
671.cpp
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
class Solution {
public:
int findSecondMinimumValue(TreeNode* root) {
vector<int>A;
treetraversal(root,A);
map<int,int>mp1;
int key;
int value=0;
for(int i=0;i<A.size();i++){
key=A[i];
mp1[key]++;
}
map<int,int> :: iterator it;
int count=0;
int pp;
for(it=mp1.begin();it!=mp1.end();++it){
cout<<it->first<<endl;
if(count==1){
pp=it->first;
}
count++;
}
if(count<=1){
return -1;
}
return pp;
}
void treetraversal(TreeNode * root,vector<int>&A){
if(root==NULL){
return ;
}
treetraversal(root->left,A);
A.push_back(root->val);
treetraversal(root->right,A);
}
};