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;
    }
};
相关推荐
wabs66613 小时前
关于贪心算法的思考
算法·贪心算法
社交怪人14 小时前
【判断大小】信息学奥赛一本通C语言解法(题号1043)
算法
Snasph14 小时前
GNU Make 用户手册(中文版)
服务器·算法·gnu
江澎涌14 小时前
拆解与 AI 的一次对话
人工智能·算法·程序员
sheeta199815 小时前
LeetCode 每日一题笔记 日期:2026.06.02 题目:3635. 最早完成陆地和水上游乐设施的时间 II
笔记·算法·leetcode
Lsk_Smion15 小时前
力扣实训 _ [102].层序遍历--前序--后续_递归与非递归的实现
数据结构·算法·leetcode
Lsk_Smion16 小时前
力扣实训 _ [25].K个一组链表
数据结构·链表
小欣加油16 小时前
leetcode3751 范围内总波动值I
java·数据结构·c++·算法·leetcode
代码中介商17 小时前
C++左值与右值:核心判断法则详解
开发语言·c++
玖玥拾17 小时前
C/C++ 基础笔记(七)
c语言·c++