-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path414.cpp
More file actions
37 lines (34 loc) · 679 Bytes
/
Copy path414.cpp
File metadata and controls
37 lines (34 loc) · 679 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
class Solution
{
public:
int thirdMax(vector<int> &a)
{
map<int, int> m;
int n = a.size();
for (int i = 0; i < n; ++i)
{
++m[a[i]];
}
if (m.size() >= 3)
{
auto it = m.end();
int i = 0;
while (i < 3)
{
++i;
--it;
}
return it->first;
}
else
{
auto it = m.end();
--it;
// if(m.size()==2)
// {
// ++it;
// }
return it->first;
}
}
};