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;
    }
};
相关推荐
我想吃余15 分钟前
【C++篇】C++11:线程库
开发语言·c++
CSDN_RTKLIB25 分钟前
【静态初始化与动态初始化】术语对比
开发语言·c++
WhereIsMyChair36 分钟前
DPO 核心损失函数β调大可以控制不偏离ref模型太远
人工智能·算法·机器学习
智者知已应修善业38 分钟前
【组合数】2024-3-16
c语言·c++·经验分享·笔记·算法
天上飞的粉红小猪1 小时前
线程同步与互斥
linux·开发语言·c++
追烽少年x1 小时前
第二章 操作符(Operators)
c++
l1t1 小时前
将利用30行X算法求解数独的python程序转成DuckDB自定义函数并比较性能
数据库·python·算法·duckdb
墨雪不会编程1 小时前
C++【string篇2】:从零基础开始到熟悉使用string类
java·开发语言·c++
花间流风2 小时前
【王阳明代数讲义】2025年CSDN花间流风博文技术汇总
算法·年终总结·模型·情感分析·王阳明代数
DuHz2 小时前
亚毫米波FMCW脉冲多普勒雷达:粒子云动态特性表征技术深度解析
论文阅读·物联网·算法·信息与通信·毫米波雷达