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;
    }
};
相关推荐
bin9153几秒前
当AI化身Git管家:初级C++开发者的版本控制焦虑与创意逆袭——老码农的幽默生存指南
c++·人工智能·git·工具·ai工具
自由生长202411 分钟前
C++折叠表达式完全指南:从打印函数到空包处理的深入解析
c++·后端
zore_c14 分钟前
【C语言】文件操作详解1(文件的打开与关闭)
c语言·开发语言·数据结构·c++·经验分享·笔记·算法
聊天QQ:48773927815 分钟前
哈里斯鹰算法的改进:融合自然与光学智慧的优化探索
数据结构
wbs_scy16 分钟前
C++ :手写 List 容器实战(从双向链表原理到完整功能落地,附源码与测试验证)
数据结构·链表
资深web全栈开发16 分钟前
[特殊字符] LeetCode 2141:如何让 N 台电脑续航最久?——“二分答案“套路一文讲透
算法·leetcode
还下着雨ZG17 分钟前
VC6.0:Window平台专属的C/C++集成开发环境(IDE)
c语言·c++·ide
刃神太酷啦21 分钟前
C++的IO流和C++的类型转换----《Hello C++ Wrold!》(29)--(C/C++)
java·c语言·开发语言·c++·qt·算法·leetcode
稚辉君.MCA_P8_Java22 分钟前
Gemini永久会员 哈希表(Hash Table)高效的数据结构
java·数据结构·后端·算法·架构
大海里的番茄24 分钟前
让操作系统的远程管理更简单用openEuler+cpolar
linux·c语言·c++