[LeetCode] Unique Number of Occurrences

1207. Unique Number of Occurrences

Given an array of integers arr, return true if the number of occurrences of each value in the array is unique, or false otherwise.

1
2
3
4
5
6
7
8
9
10
class Solution {
public:
bool uniqueOccurrences(vector<int>& arr) {
unordered_map<int, int> mp;
unordered_set<int> us;
for(auto a : arr) mp[a]++;
for(auto [_, c] : mp) us.insert(c);
return us.size() == mp.size();
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/11/30/PS/LeetCode/unique-number-of-occurrences/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.