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;
    }
};
相关推荐
bIo7lyA8v22 分钟前
算法稳定性分析中的输入扰动建模的技术9
算法
CoderCodingNo26 分钟前
【GESP】C++三级真题 luogu-B4499, [GESP202603 三级] 二进制回文串
数据结构·c++·算法
sinat_2869451927 分钟前
AI Coding 时代的 TDD:从理念到工程落地
人工智能·深度学习·算法·tdd
ASKED_201937 分钟前
从排序到生成:腾讯广告算法大赛 2025 baseline解读
人工智能·算法
田梓燊1 小时前
leetcode 160
算法·leetcode·职场和发展
_深海凉_1 小时前
LeetCode热题100-颜色分类
python·算法·leetcode
网安INF1 小时前
数据结构第三章:栈、队列和数组
数据结构
hetao17338372 小时前
2026-04-09~12 hetao1733837 的刷题记录
c++·算法
6Hzlia2 小时前
【Hot 100 刷题计划】 LeetCode 136. 只出现一次的数字 | C++ 哈希表&异或基础解法
c++·算法·leetcode
MWWZ2 小时前
最近的一些软件更新
opencv·算法·计算机视觉