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;
    }
};
相关推荐
jimy14 分钟前
C语言实现-----面向对象编程
c语言·数据结构
Kethy__8 分钟前
计算机中级-数据库系统工程师-数据结构-树与二叉树(2)
数据结构·数据库·软考··计算机中级
黎阳之光8 分钟前
数智技术如何赋能空天地一体化,领跑低空经济新赛道
大数据·人工智能·算法·安全·数字孪生
cch891814 分钟前
易语言与C++:编程语言终极对决
开发语言·c++
HABuo17 分钟前
【linux线程(三)】生产者消费者模型(条件变量阻塞队列版本、信号量环形队列版本)详细剖析
linux·运维·服务器·c语言·c++·ubuntu·centos
Dr.F.Arthur44 分钟前
我的算法笔记——哈希表篇
数据结构·笔记·散列表
小肝一下1 小时前
每日两道力扣,day2
c++·算法·leetcode·职场和发展
漂流瓶jz1 小时前
UVA-11846 找座位 题解答案代码 算法竞赛入门经典第二版
数据结构·算法·排序算法·深度优先·aoapc·算法竞赛入门经典·uva
米粒12 小时前
力扣算法刷题 Day 31 (贪心总结)
算法·leetcode·职场和发展
少许极端2 小时前
算法奇妙屋(四十)-贪心算法学习之路7
java·学习·算法·贪心算法