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;
    }
};
相关推荐
Bruce_Liuxiaowei5 分钟前
驴滑块拼图游戏:从19世纪的纸片谜题到数学博弈论
人工智能·算法
一直C10 分钟前
Linux系统编程|信号进阶 + SystemV IPC(消息队列、共享内存)
linux·c语言·开发语言·算法·青少年编程·vim
每周报刊32 分钟前
竞速座舱级视界:爱攻 AGP497UCZD 超宽 QDOLED 显示器解析
数据结构·游戏·计算机外设
布莱克6051 小时前
链表详解:定义、作用、应用场景及与数组的区别(C/C++ 实战)
c语言·开发语言·c++·链表
鹿角片ljp1 小时前
LeetCode 141. 环形链表|从 HashSet 到快慢指针 O (1) 空间最优解
算法·leetcode·链表
薛定e的猫咪1 小时前
(NeurIPS 2022)GraphGPS:MPNN 与全局注意力的融合之道
人工智能·深度学习·学习·算法
执子星海2 小时前
Registry Win32 API详解
c++·windows·microsoft·visualstudio·微软
AI服务老曹2 小时前
车牌识别算法接入AI视频分析平台的流程和误报优化
人工智能·算法·音视频
江屿风2 小时前
C++OJ题经验总结(竞赛)5
开发语言·c++
神威难绷泪2 小时前
Linux应用软件编程:线程分离属性 互斥机制 同步机制 死锁
linux·开发语言·算法·线程