unique-number-of-occurrences
1.0.0
Unique Number of Occurrences
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1
#include <bits/stdc++.h>
2
3
using namespace
std;
4
5
class
Solution
6
{
7
public
:
8
bool
uniqueOccurrences
(vector<int>& arr)
9
{
10
unordered_map<int, int> occurrences;
// key: element from array; value: number of occurrences
11
for
(
int
el: arr)
12
occurrences[el]++;
13
14
set<int> unique_occurrences;
15
for
(pair<int, int> pairs: occurrences)
16
{
17
int
el = pairs.second;
18
if
(unique_occurrences.find(el) != unique_occurrences.end())
19
return
false
;
20
else
21
unique_occurrences.insert(el);
22
}
23
return
true
;
24
}
25
};
26
27
int
main
()
28
{
29
30
return
0;
31
}
Solution
Definition
main.cpp:6
Solution::uniqueOccurrences
bool uniqueOccurrences(vector< int > &arr)
Definition
main.cpp:8
main
int main()
Definition
main.cpp:27
main.cpp
Generated by
1.9.8