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;
    }
};
相关推荐
yxc_inspire1 小时前
基于Qt的app开发第十四天
前端·c++·qt·app·面向对象·qss
蒟蒻小袁2 小时前
力扣面试150题--实现Trie(前缀树)
leetcode·面试·c#
电院工程师2 小时前
轻量级密码算法CHAM的python实现
python·嵌入式硬件·算法·安全·密码学
大白曾是少年2 小时前
哈希表三种数据结构在leetcode中的使用情况分析
数据结构·leetcode·散列表
Cai junhao2 小时前
【Qt】工具介绍和信号与槽机制
开发语言·c++·qt·qt6.3
@老蝴8 小时前
C语言 — 通讯录模拟实现
c语言·开发语言·算法
L-ololois8 小时前
【AI】模型vs算法(以自动驾驶为例)
人工智能·算法·自动驾驶
安全系统学习9 小时前
网络安全之RCE简单分析
开发语言·python·算法·安全·web安全
byte轻骑兵11 小时前
【C++特殊工具与技术】优化内存分配(四):定位new表达式、类特定的new、delete表达式
开发语言·c++
TGB-Earnest11 小时前
【leetcode-合并两个有序链表】
javascript·leetcode·链表