LeetCode/cpp/unique-number-of-occurrences.cpp
Matej Focko 8d4eb729b4
cpp: add “1207. Unique Number of Occurrences”
Signed-off-by: Matej Focko <mfocko@redhat.com>
2024-01-22 11:36:18 +01:00

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