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;
    }
};
相关推荐
阿Y加油吧2 分钟前
力扣滑动窗口两大压轴题:最小覆盖子串 + 滑动窗口最大值(保姆级思路 + 代码详解)
算法·leetcode·职场和发展
森G4 分钟前
30、QStandardItemModel 和 QTableView---------Model/View模型视图
c++·qt
maxmaxma7 分钟前
ROS2机器人少年创客营:Python第二课
c++·python·机器人
北顾笙98011 分钟前
day11-数据结构力扣
数据结构·算法·leetcode
山栀shanzhi14 分钟前
FFmpeg 实战:RGB 裸流编码成 MP4,全流程详解(含源码
c++·ffmpeg
Yupureki17 分钟前
《Linux系统编程》20.常见程序设计模式
linux·服务器·c语言·c++·单例模式·建造者模式·责任链模式
月落归舟22 分钟前
Lambda + Arrays---小练习
数据结构·算法
SilentSlot24 分钟前
[数据结构]B树的基本定义和操作
数据结构·b树·前端框架
2601_9553544624 分钟前
seo臻系统和百度seo有什么区别
算法
誰能久伴不乏28 分钟前
给开发板装上嘴巴与耳朵:i.MX6ULL 裸机串口 (UART) 驱动终极指南
arm开发·c++·单片机·嵌入式硬件·arm