-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
1133.cpp
38 lines (35 loc) · 1.02 KB
/
1133.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
37
38
__________________________________________________________________________________________________
class Solution {
public:
int largestUniqueNumber(vector<int>& A) {
sort(begin(A), end(A));
while (A.size() >= 2 and A.back() == A[A.size() - 2]) {
int x = A.back();
while (!A.empty() and A.back() == x) {
A.pop_back();
}
}
if (A.empty()) {
return -1;
}
return A.back();
}
};
__________________________________________________________________________________________________
class Solution {
public:
int largestUniqueNumber(vector<int>& A) {
map<int,int> M;
int ans = -1;
for(int num : A) {
M[num]++;
}
for(auto KV : M) {
if(KV.second == 1) {
ans = max(ans,KV.first);
}
}
return ans;
}
};
__________________________________________________________________________________________________