Unique Number of Occurrences Solutions in C++
Number 1207
Difficulty Easy
Acceptance 71.6%
Link LeetCode
Other languages Go
Solutions
C++ solution by haoel/leetcode
// Source : https://leetcode.com/problems/unique-number-of-occurrences/// Author : Manu Gond// Date : 2019-10-06class Solution {public:bool uniqueOccurrences(vector<int>& arr) {map<int,int>myMap;for(int i=0;i<arr.size();i++){myMap[arr[i]]++;}int temp=0;vector<int>v;for (auto i : myMap) {v.push_back(i.second);}sort(v.begin(),v.end());for(int i=0;i<v.size();i++){if(v[i]==temp)return false;elsetemp=v[i];}return true;}};
C++ solution by liuyubobobo/Play-Leetcode
/// Source : https://leetcode.com/problems/unique-number-of-occurrences//// Author : liuyubobobo/// Time : 2019-09-28#include <iostream>#include <vector>#include <unordered_map>using namespace std;/// Using HashMap/// Time Complexity: O(n)/// Space Complexity: O(n)class Solution {public:bool uniqueOccurrences(vector<int>& arr) {unordered_map<int, int> freq;for(int e: arr) freq[e] ++;unordered_map<int, int> res;for(const pair<int, int>& p: freq)if(res.count(p.second)) return false;else res[p.second] ++;return true;}};int main() {return 0;}