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;
    }
};
相关推荐
xiaoye-duck2 分钟前
C++ STL map 系列深度解析:从底层原理、核心接口到实战场景
开发语言·c++·stl
2201_758642645 分钟前
嵌入式C++开发注意事项
开发语言·c++·算法
闻哥18 分钟前
MySQL InnoDB 缓存池(Buffer Pool)详解:原理、结构与链表管理
java·数据结构·数据库·mysql·链表·缓存·面试
AI科技星18 分钟前
基于v≡c第一性原理的大统一力方程:严格推导、全维度验证与四大基本相互作用的统一
人工智能·线性代数·算法·机器学习·平面
小杍随笔20 分钟前
【Rust 语言编程知识与应用:同步机制详解】
开发语言·算法·rust
sprite_雪碧22 分钟前
枚举 / 搜索类算法(机试核心考点)
算法
罗湖老棍子28 分钟前
简单题(信息学奥赛一本通- P1539)
数据结构·算法·树状数组·区间修改 单点查询
圣保罗的大教堂34 分钟前
leetcode 1594. 矩阵的最大非负积 中等
leetcode
羊小猪~~35 分钟前
【论文精度】Transformer---大模型基石
人工智能·深度学习·考研·算法·机器学习·transformer
西西弟1 小时前
常见排序算法集合(数据结构)
数据结构·算法·排序算法