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;
    }
};
相关推荐
꧁Q༒ོγ꧂21 小时前
C++ 入门完全指南(四)--函数与模块化编程
开发语言·c++
byzh_rc21 小时前
[认知计算] 专栏总结
线性代数·算法·matlab·信号处理
汉克老师21 小时前
GESP2025年12月认证C++八级真题与解析(判断题8-10)
c++·快速排序··lcs·gesp八级·gesp8级
qq_4335545421 小时前
C++ manacher(求解回文串问题)
开发语言·c++·算法
歌_顿21 小时前
知识蒸馏学习总结
人工智能·算法
圣保罗的大教堂1 天前
leetcode 1161. 最大层内元素和 中等
leetcode
闲看云起1 天前
LeetCode-day6:接雨水
算法·leetcode·职场和发展
没学上了1 天前
VLM_一维离散卷积与二维离散卷积(还是复习感觉还行)
算法
HL_风神1 天前
设计原则之迪米特
c++·学习·设计模式
黛色正浓1 天前
leetCode-热题100-贪心合集(JavaScript)
javascript·算法·leetcode