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;
    }
};
相关推荐
yzx9910137 小时前
Python数据结构入门指南:从基础到实践
开发语言·数据结构·python
消失的旧时光-19438 小时前
智能指针(二):机制篇 —— 移动语义与所有权转移
c++·智能指针
ValhallaCoder8 小时前
hot100-堆
数据结构·python·算法·
小小小米粒8 小时前
函数式接口 + Lambda = 方法逻辑的 “插拔式解耦”
开发语言·python·算法
风吹乱了我的头发~8 小时前
Day31:2026年2月21日打卡
开发语言·c++·算法
mjhcsp9 小时前
C++ 后缀平衡树解析
android·java·c++
D_evil__9 小时前
【Effective Modern C++】第六章 lambda表达式:33. 对于auto&&形参使用decltype以及forward它们
c++
望舒5139 小时前
代码随想录day33,动态规划part2
java·算法·leetcode·动态规划
那起舞的日子9 小时前
牛客网刷算法的启发
算法
追随者永远是胜利者9 小时前
(LeetCode-Hot100)169. 多数元素
java·算法·leetcode·go