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;
    }
};
相关推荐
梨子串桃子_1 小时前
推荐系统学习笔记 | PyTorch学习笔记
pytorch·笔记·python·学习·算法
夏鹏今天学习了吗2 小时前
【LeetCode热题100(83/100)】最长递增子序列
算法·leetcode·职场和发展
暮色_年华2 小时前
随想 2:对比 linux内核侵入式链表和 STL 非侵入链表
linux·c++·链表
情缘晓梦.2 小时前
C语言指针进阶
java·开发语言·算法
北邮刘老师3 小时前
智能体治理:人工智能时代信息化系统的全新挑战与课题
大数据·人工智能·算法·机器学习·智能体互联网
w-w0w-w3 小时前
C++模板参数与特化全解析
开发语言·c++
AlenTech3 小时前
155. 最小栈 - 力扣(LeetCode)
算法·leetcode·职场和发展
mit6.8243 小时前
正反两次扫描|单调性cut
算法
Yzzz-F4 小时前
牛客小白月赛127 E
算法
大锦终4 小时前
递归回溯综合练习
c++·算法·深度优先