mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
22 lines
484 B
C++
22 lines
484 B
C++
|
#include <map>
|
||
|
#include <set>
|
||
|
#include <vector>
|
||
|
|
||
|
class Solution {
|
||
|
public:
|
||
|
bool uniqueOccurrences(const std::vector<int> &arr) {
|
||
|
std::map<int, std::size_t> freqs;
|
||
|
for (const auto &x : arr) {
|
||
|
++freqs[x];
|
||
|
}
|
||
|
|
||
|
// get unique values
|
||
|
std::set<std::size_t> unique_counts;
|
||
|
for (const auto &[key, count] : freqs) {
|
||
|
unique_counts.insert(count);
|
||
|
}
|
||
|
|
||
|
return freqs.size() == unique_counts.size();
|
||
|
}
|
||
|
};
|