1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-20 01:56:57 +02:00
LeetCode/cpp/unique-number-of-occurrences.cpp

22 lines
484 B
C++
Raw Normal View History

#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();
}
};