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;
    }
};
相关推荐
每天回答3个问题几秒前
LeetCodeHot100|图、994.腐烂的橘子、207.课程表、208.实现Trie前缀树
c++·
吃好睡好便好5 分钟前
在Matlab中绘制马鞍函数曲面图
开发语言·人工智能·学习·算法·matlab·信息可视化
wa的一声哭了6 分钟前
Mit6.s081 Interrupts and device driver(中断和设备驱动)
linux·服务器·arm开发·数据库·python·gpt·算法
许长安11 分钟前
gRPC 数据包传输格式解析:从 Protobuf 到 HTTP/2
c++·经验分享·笔记·http·rpc
渡我白衣15 分钟前
定时器与时间轮思想
linux·开发语言·前端·c++·人工智能·深度学习·神经网络
luyun02020216 分钟前
实用小工具,吾爱出品
开发语言·c++·算法
蜡笔小马18 分钟前
06.C++设计模式-装饰模式
c++·设计模式·装饰器模式
宏笋21 分钟前
C++11使用chrono获取当前时间戳
c++
NNYSJYKJ23 分钟前
K12 学习常见问题破解:脑能思维链的算法与教育应用
学习·算法
Shadow(⊙o⊙)27 分钟前
硬核手搓解析!进程-内核分析:命令行参数及环境变量,重构main()
linux·运维·服务器·开发语言·c++·后端·学习