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;
    }
};
相关推荐
Brilliantwxx5 分钟前
【Linux】 进程(4)七大进程状态深度解析
linux·运维·算法
青少儿编程课堂21 分钟前
用图形化编程做一个“少年探险闯关”小游戏:方向键控制、碰撞检测与多关卡串起完整项目
c++·python·算法·bfs·信息学竞赛
liulilittle40 分钟前
长上下文的成本结构与「甜点区间」——从推理引擎的物理约束看 200K/256K/400K
c++·人工智能·ai·llm·注意力·qkv
十五年专注C++开发42 分钟前
100w条数据丝滑滚动!Qt Model/View 架构实战(二)
开发语言·c++·qt
CQU_JIAKE1 小时前
8.22【A】
算法
二十雨辰1 小时前
[Java]-数据集合
数据结构
skr爱码士1 小时前
06_Qt 常用数据类型与容器:QString、QList、QVector、QMap 的性能与实现分析
开发语言·c++·qt
大熊背2 小时前
ISP图像处理中大数乘法溢出处理(一)
人工智能·python·算法·溢出处理
奶茶树2 小时前
【C++】13. C++11新特性【上】
c语言·开发语言·c++·git·github
吴声子夜歌2 小时前
Java面试——数据结构(一)
java·数据结构·面试