unique-number-of-occurrences 1.0.0
Unique Number of Occurrences
Loading...
Searching...
No Matches
Solution Class Reference

Public Member Functions

bool uniqueOccurrences (vector< int > &arr)
 

Detailed Description

Definition at line 5 of file main.cpp.

Member Function Documentation

◆ uniqueOccurrences()

bool Solution::uniqueOccurrences ( vector< int > &  arr)
inline

Definition at line 8 of file main.cpp.

9 {
10 unordered_map<int, int> occurrences; // key: element from array; value: number of occurrences
11 for (int el: arr)
12 occurrences[el]++;
13
14 set<int> unique_occurrences;
15 for (pair<int, int> pairs: occurrences)
16 {
17 int el = pairs.second;
18 if (unique_occurrences.find(el) != unique_occurrences.end())
19 return false;
20 else
21 unique_occurrences.insert(el);
22 }
23 return true;
24 }

The documentation for this class was generated from the following file: