cpp: add “1207. Unique Number of Occurrences”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
3d625eaade
commit
8d4eb729b4
1 changed files with 21 additions and 0 deletions
21
cpp/unique-number-of-occurrences.cpp
Normal file
21
cpp/unique-number-of-occurrences.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#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();
|
||||
}
|
||||
};
|
Loading…
Add table
Reference in a new issue