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;
    }
};
相关推荐
青梅橘子皮9 小时前
string---入门OJ题(1)
数据结构·算法
qq_416409139 小时前
专业的openclaw推荐
c++
qq_4542450310 小时前
BasicMethod.Map 设计框架:8 个并行基础模块的数学根基与实现
数据结构·算法·c#
青山木10 小时前
Hot 100 --- 二叉树与递归
java·数据结构·算法·leetcode·深度优先
珠海西格电力10 小时前
数据采集与治理:零碳园区管理系统的 “生命线”
大数据·人工智能·算法·架构·能源
●VON11 小时前
HarmonyKit | 鸿蒙新特性:router 导航 API 从 pushUrl 到 UIContext 的演进
算法·华为·交互·harmonyos
星释11 小时前
鸿蒙智能体开发实战:31.鸿蒙壁纸大师 - 环境搭建与基础配置
算法·华为·ai·harmonyos·鸿蒙
一个小猴子`11 小时前
CUDA全局内存
c++·cuda编程
ysa05103011 小时前
【板子】树上启发式合并
数据结构·c++·笔记·算法
Simple_core11 小时前
cmake模板和问题总结
c++