rename it

This commit is contained in:
Jidong Xiao
2023-10-23 00:23:46 -04:00
parent edcc52f3d5
commit 46d75f0902

View File

@@ -0,0 +1,26 @@
class Solution {
public:
bool uniqueOccurrences(vector<int>& arr) {
int size = arr.size();
// key: number, value: occurrence
std::map<int, int> map1;
std::set<int> set1;
// create the map
for(int i=0; i<size; i++){
map1[arr[i]]++;
}
// use the map
std::map<int, int>::iterator itr;
itr = map1.begin();
while(itr != map1.end()){
// if this number of occurrence already exists
if(set1.find(itr->second) != set1.end()){
return false;
}
// otherwise, store it.
set1.insert(itr->second);
itr++;
}
return true;
}
};