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;
    }
};
相关推荐
YSL07012415 小时前
线性表和顺序表
数据结构
6Hzlia15 小时前
【Classic 150 刷题计划】 LeetCode 274. H 指数 | C++ 二分答案法 (单调性降维打击)
c++·算法·leetcode
行者全栈架构师15 小时前
WorkBuddy 实战:50 份简历 30 分钟筛完,还能自动出评估报告
人工智能·算法·微信
huang57914715 小时前
数据结构的抽象化与接口复用设计理念4
数据结构
动词ing15 小时前
【学习笔记】数据结构(链表合并 双指针合并有序链表)
数据结构·笔记·学习
ysu_031415 小时前
19-插入排序与希尔排序
数据结构·算法·排序算法
qq_5085760915 小时前
人性机器人部分 算法
算法·机器人
Polevne16 小时前
C# GRPC 一元与双向流
linux·算法·c#
huang57914716 小时前
复杂网络中的最短路径搜索算法性能分析3
算法
找方案16 小时前
AI+气象预报:华为盘古大模型如何让天气预报精准到街区
人工智能·算法·机器学习