LeetCode75——Day21

文章目录

一、题目

1207. Unique Number of Occurrences

Given an array of integers arr, return true if the number of occurrences of each value in the array is unique or false otherwise.

Example 1:

Input: arr = 1,2,2,1,1,3

Output: true

Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.

Example 2:

Input: arr = 1,2

Output: false

Example 3:

Input: arr = -3,0,1,-3,1,1,1,-3,10,0

Output: true

Constraints:

1 <= arr.length <= 1000

-1000 <= arri <= 1000

二、题解

cpp 复制代码
class Solution {
public:
    bool uniqueOccurrences(vector<int>& arr) {
        unordered_map<int,int> map;
        unordered_map<int,int> times;
        unordered_map<int,int>::iterator it; 
        int n = arr.size();
        for(int i = 0;i < n;i++){
            map[arr[i]]++;
        }
        for (it = map.begin(); it != map.end();it++){
            if(times[map[it->first]] == 0) times[map[it->first]]++;
            else return false;
        }
        return true;
    }
};
相关推荐
lisw0513 分钟前
发酵算法两大应用方向解析
算法·数学建模
布莱克60516 分钟前
C++ 内存泄漏全解析:常见场景、成因与规避实践
开发语言·c++·内存泄露
jimy124 分钟前
lvalue、xvalue、prvalue(一):三者的分类
开发语言·c++
动词ing1 小时前
【题目练习】全排列
算法
HAPPY酷1 小时前
C++ 内存泄漏排查:从裸 new 到 RAII 修复,附 ASan 实战
开发语言·c++
易小尊1 小时前
Dixon-Coles 的 τ 函数,我写错了三次
算法
凯瑟琳.奥古斯特2 小时前
力扣1015C++解法技巧
c++·算法·leetcode·链表·职场和发展
seowmt3 小时前
GEO效果该什么时候看数据:从立项到复盘的时间线复盘
算法·ip·seo·geo·faq
悠仁さん3 小时前
【算法C++】双指针(一)
数据结构·c++·算法
文丑颜不良啊3 小时前
LeetCode626~650题目解析
java·leetcode