1207. Unique Number of Occurrences 發表於 2023-12-21 | 分類於 leetcode problemsolution123456789101112131415class Solution {public: bool uniqueOccurrences(vector<int>& arr) { unordered_map<int, int> mp; unordered_set<int> s; for(int a:arr) mp[a]++; for(auto it = mp.begin() ; it!=mp.end() ; ++it) { if(s.count(it->second)) return false; s.insert(it->second); } return true; }}; analysis time complexity O(n) space complexity O(n)