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;
    }
};
相关推荐
yesyesido14 小时前
3D在线魔方模拟器
科技·算法·3d·生活·业界资讯·交友·帅哥
王老师青少年编程14 小时前
线性DP第12课:线性DP应用案例实践:数字三角形
c++·动态规划·dp·线性dp·csp·信奥赛·数字三角形
是苏浙14 小时前
蓝桥杯备战day1
算法
汉克老师14 小时前
CCF-NOI2025第一试题目与解析(第二题、序列变换(sequence))
c++·算法·动态规划·noi
hweiyu0014 小时前
数据结构:字典
数据结构
A charmer14 小时前
内存泄漏、死锁:定位排查工具+解决方案(C/C++ 实战指南)
c语言·开发语言·c++
断剑zou天涯14 小时前
【算法笔记】KMP算法
java·笔记·算法
程序员东岸14 小时前
《数据结构——排序(下)》分治与超越:快排、归并与计数排序的终极对决
数据结构·c++·经验分享·笔记·学习·算法·排序算法
无限进步_14 小时前
C++初始化列表详解:语法、规则与最佳实践
java·开发语言·数据库·c++·git·github·visual studio
某林21214 小时前
在slam建图中为何坐标base_link,laser,imu_link是始终在一起的,但是odom 会与这位三个坐标在运行中产生偏差
人工智能·算法