Skip to content

Commit d5e7145

Browse files
authored
Create unique-number-of-occurrences.cpp
1 parent 0847324 commit d5e7145

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

C++/unique-number-of-occurrences.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Time: O(n)
2+
// Space: O(n)
3+
4+
class Solution {
5+
public:
6+
bool uniqueOccurrences(vector<int>& arr) {
7+
unordered_map<int, int> count;
8+
for (const auto& a : arr) {
9+
++count[a];
10+
}
11+
unordered_set<int> lookup;
12+
for (const auto& [k, v] : count) {
13+
if (lookup.count(v)) {
14+
return false;
15+
}
16+
lookup.emplace(v);
17+
}
18+
return true;
19+
}
20+
};

0 commit comments

Comments
 (0)