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 <= arri <= 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;
    }
};
相关推荐
码匠许师傅1 小时前
【C++三方组件】mbedTLS:面向嵌入式的轻量 TLS
开发语言·c++
叉烧滑蛋1 小时前
B站台湾大学郭彦甫|MATLAB 学习笔记|04 变量与档案存取
数据结构
?re?ta?rd?ed?1 小时前
C++11新特性,{}与左值
c++·windows
j7~2 小时前
【穷举、深搜与回溯算法】一棵决策树讲透全排列与子集
数据结构·c++·算法·leetcode·回溯·递归
傅科摆 _ py3 小时前
DP,贪心,堆和栈,二分力扣复习
开发语言·python·算法
kiracrimson3 小时前
栈与队列容器:适配器、deque 与 priority_queue
开发语言·c++·适配器模式
Shaoshing3 小时前
LeetCode100 42.接雨水
java·算法·leetcode
域限奇点访客3 小时前
用AI生成问卷的网站怎么选?看题目录入结构、题型映射和生成后的校验
算法
文丑颜不良啊4 小时前
LeetCode1261~1280题目解析
java·leetcode
qq_466302454 小时前
如何通过部分文件名,读取出整个文件名
c++·qt