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;
    }
};
相关推荐
2301_818419013 分钟前
C++中的协程编程
开发语言·c++·算法
add45a5 分钟前
C++中的工厂方法模式
开发语言·c++·算法
無限進步D13 分钟前
二分算法 cpp
算法
xushichao198913 分钟前
C++中的工厂模式高级应用
开发语言·c++·算法
2501_9249526921 分钟前
C++模块化编程指南
开发语言·c++·算法
qzhqbb21 分钟前
差分隐私与大模型+差分隐私在相关领域应用的论文总结
人工智能·算法
2401_8319207425 分钟前
基于C++的爬虫框架
开发语言·c++·算法
我是咸鱼不闲呀25 分钟前
力扣Hot100系列22(Java)——[图论]总结(岛屿数量,腐烂的橘子,课程表,实现Trie(前缀树))
java·leetcode·图论
MSTcheng.31 分钟前
【优选算法必修篇——位运算】『面试题 01.01. 判定字符是否唯一&面试题 17.19. 消失的两个数字』
java·算法·面试
weixin_4219226932 分钟前
模板元编程性能分析
开发语言·c++·算法