-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1207.cpp
More file actions
30 lines (27 loc) · 807 Bytes
/
1207.cpp
File metadata and controls
30 lines (27 loc) · 807 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
class Solution {
public:
bool uniqueOccurrences(vector<int>& arr) {
vector<short> record(2001, 0);
vector<bool> visited(2001, false);
for (auto num : arr) record[num + 1000]++;
for (int i = 0; i < 2001; i++) {
if (record[i] == 0) continue;
if (visited[record[i]] == true) return false;
visited[record[i]] = true;
}
return true;
}
};
class Solution {
public:
bool uniqueOccurrences(vector<int>& arr) {
unordered_map<int, int> cnt;
for (auto& num : arr) cnt[num]++;
unordered_set<int> occurence;
for (auto& [num, appear] : cnt) {
if (occurence.count(appear)) return false;
occurence.insert(appear);
}
return true;
}
};