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;
    }
};
相关推荐
易只轻松熊16 分钟前
C++(21):fstream的读取和写入
开发语言·c++
小葡萄202521 分钟前
黑马程序员C++2024新版笔记 第三章 数组
笔记·算法·c++20
虾球xz1 小时前
游戏引擎学习第292天:实现蛇
c++·学习·游戏引擎
勇闯逆流河7 小时前
【数据结构】堆
c语言·数据结构·算法
jjkkzzzz7 小时前
Linux下的c/c++开发之操作Redis数据库
数据库·c++·redis
pystraf7 小时前
LG P9844 [ICPC 2021 Nanjing R] Paimon Segment Tree Solution
数据结构·c++·算法·线段树·洛谷
Funny-Boy8 小时前
菱形继承原理
c++
飞川撸码8 小时前
【LeetCode 热题100】739:每日温度(详细解析)(Go语言版)
算法·leetcode·golang
yuhao__z9 小时前
代码随想录算法训练营第六十六天| 图论11—卡码网97. 小明逛公园,127. 骑士的攻击
算法
Echo``9 小时前
3:OpenCV—视频播放
图像处理·人工智能·opencv·算法·机器学习·视觉检测·音视频