zl程序教程

您现在的位置是:首页 >  其他

当前栏目

leetcode 1207 独一无二的出现次数

LeetCode 出现 次数
2023-09-27 14:29:24 时间

独一无二的出现次数

双map

class Solution {
public:
    bool uniqueOccurrences(vector<int>& arr) {
        map<int ,int> my_map;
        map<int ,int> my_map2;

        for(int i=0 ;i<arr.size() ;i++)
            my_map[arr[i]]++;
        
        for(auto it:my_map)
            my_map2[it.second]++;
        
        for(auto it:my_map2)
            if(it.second != 1) return false;
        
        return true;
    }
};