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;
    }
};
相关推荐
嫂子开门我是_我哥6 分钟前
心电域泛化研究从0入门系列 | 第二篇:心电信号预处理全攻略——扫清域泛化建模的第一道障碍
人工智能·算法·ecg
wefg130 分钟前
【算法】算数基本定理、分解质因数
算法
j_xxx404_33 分钟前
力扣困难算法精解:串联所有单词的子串与最小覆盖子串
java·开发语言·c++·算法·leetcode·哈希算法
挠头猴子36 分钟前
一个数组去重,两个数组找不同或相同
数据结构·算法
big_rabbit05021 小时前
[算法][力扣167]Two Sum II
算法·leetcode·职场和发展
颜酱1 小时前
二分图核心原理与判定算法
javascript·后端·算法
筱砚.1 小时前
C++——lambda
开发语言·c++·算法
Eward-an2 小时前
LeetCode 76. 最小覆盖子串(详细技术解析)
python·算法·leetcode·职场和发展
guygg882 小时前
基于ADMM的MRI-PET高质量图像重建算法MATLAB实现
开发语言·算法·matlab
李昊哲小课2 小时前
Python itertools模块详细教程
数据结构·python·散列表