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;
    }
};
相关推荐
晚风叙码2 小时前
《C++基础进阶:函数重载、引用、inline与nullptr全解析》
c++
雪度娃娃2 小时前
ASIO异步通信——服务器网络层和逻辑层设计
开发语言·网络·c++·php
Han.miracle2 小时前
Java HashMap 与 ConcurrentHashMap 核心原理总结:从 Hash 冲突到 LongAdder
java·算法·哈希算法
菜菜的顾清寒2 小时前
力扣HOT100(35)回溯-全排列
算法·leetcode·职场和发展
Zhang~Ling2 小时前
C++ 多态完全指南:虚函数、重写、虚表与动态绑定深度解析
开发语言·c++
BestOrNothing_20152 小时前
C++零基础到工程实战(5.2.5):函数默认参数和函数重载
c++·函数重载·函数默认参数·nullptr·函数声明与定义
不负岁月无痕2 小时前
STL-- C++ list类 模拟实现
开发语言·c++·list
weixin_468466852 小时前
目标识别算法落地实战:从选型到部署的全流程指南
图像处理·人工智能·python·算法·目标检测·机器视觉·目标识别
MicroTech20252 小时前
微算法科技(NASDAQ :MLGO)量子启发进化算法(QEA)与区块链(BC)集成技术:构建高可靠去中心化创新方案
科技·算法·量子计算
CQU_JIAKE3 小时前
5.27【A】
算法