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;
    }
};
相关推荐
Kk.080216 分钟前
项目《基于Linux下的mybash命令解释器》(一)
前端·javascript·算法
xiaotao13134 分钟前
01-编程基础与数学基石: Python核心数据结构完全指南
数据结构·人工智能·windows·python
SteveSenna35 分钟前
Trossen Arm MuJoCo自定义1:改变目标物体
人工智能·学习·算法·机器人
Hical_W1 小时前
为 C++ Web 框架设计三层 PMR 内存池:从原理到实战
c++·github
yong99901 小时前
IHAOAVOA:天鹰优化算法与非洲秃鹫优化算法的混合算法(Matlab实现)
开发语言·算法·matlab
BestOrNothing_20151 小时前
C++零基础到工程实战(3.6):逻辑实战示例—日志模块
c++·命令行参数·main函数·switch case·逻辑判断·if else·enum class
t***5441 小时前
有哪些常见的架构设计模式在现代C++中应用
开发语言·c++
米粒12 小时前
力扣算法刷题 Day 42(股票问题总结)
算法·leetcode·职场和发展
zopple2 小时前
汇编、C、C++和Java核心技术对比
c语言·汇编·c++
汉克老师3 小时前
GESP2024年3月认证C++三级( 第三部分编程题(1、字母求和)
c++·string·gesp三级·gesp3级·大小写判断