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 <= arr[i] <= 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;
    }
};
相关推荐
故事和你9114 小时前
sdut-程序设计基础Ⅰ-实验三while循环(1-10)
开发语言·数据结构·c++·算法·类和对象
再一次等风来14 小时前
声源定位算法5----SRP-PHAT(1)
算法·信号处理·srp
Yupureki14 小时前
《算法竞赛从入门到国奖》算法基础:数据结构-并查集
c语言·数据结构·c++·算法
DeepModel14 小时前
【概率分布】伯努利分布详解
算法·概率论
再一次等风来14 小时前
声源定位算法5----SRP-PHAT(2)
算法·信号处理·srp·声源定位·gcc-phat
Andy14 小时前
Cpp语法1
c++·c
CappuccinoRose14 小时前
MATLAB学习文档 - 汇总篇
学习·算法·matlab
艾莉丝努力练剑14 小时前
静态地址重定位与动态地址重定位:Linux操作系统的视角
java·linux·运维·服务器·c语言·开发语言·c++
菜鸟小九14 小时前
hot100(31-40)
java·算法
gfdhy15 小时前
【Linux】服务器网络与安全核心配置|静态IP+SSH加固+防火墙,公网服务器必学实操
linux·服务器·网络·tcp/ip·算法·安全·哈希算法