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;
    }
};
相关推荐
freedom_1024_几秒前
【c++ qt】QtConcurrent与QFutureWatcher:实现高效异步计算
java·c++·qt
路弥行至15 分钟前
C语言入门教程 | 第七讲:函数和程序结构完全指南
c语言·经验分享·笔记·其他·算法·课程设计·入门教程
Xの哲學16 分钟前
Linux ioctl 深度剖析:从原理到实践
linux·网络·算法·架构·边缘计算
隐语SecretFlow28 分钟前
隐语SecreFlow:如何全面提升MPC多方安全学习的性能?
算法
minji...41 分钟前
C++ 模板进阶
开发语言·c++
AC是你的谎言1 小时前
c++仿muduo库实现高并发服务器--connection类
linux·服务器·c++·学习
王国强20091 小时前
什么是算法复杂度?
算法
fantasy5_51 小时前
手写一个C++字符串类:从底层理解String的实现
java·jvm·c++
夏鹏今天学习了吗1 小时前
【LeetCode热题100(54/100)】全排列
算法·leetcode·深度优先
緈福的街口1 小时前
gps的定位图,在车的位置去寻找周围20x20的区域,怎么确定周围有多少辆车,使用什么数据结构
数据结构·算法