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;
    }
};
相关推荐
洛水水5 分钟前
【力扣100题】25. 搜索二维矩阵 II
算法·leetcode·矩阵
样例过了就是过了5 分钟前
LeetCode热题100 多数元素
c++·算法·leetcode·贪心算法
白羊by6 分钟前
YOLOv8 官方损失函数详解(按任务分类)
人工智能·深度学习·算法·yolo·分类
nbwenren7 分钟前
C++ 资源管理 —— RAII
开发语言·c++
沪漂阿龙8 分钟前
面试题:逻辑回归是什么?为什么用 Sigmoid、对数损失、最大似然、Softmax、多分类、类别不平衡一文讲透
人工智能·算法·机器学习·分类·逻辑回归
酿情师8 分钟前
区块链原理与技术02:UTXO 模型、账户余额模型与以太坊账户体系(区块链的数据结构03)
数据结构·区块链
Shadow(⊙o⊙)15 分钟前
进程分析—从操作系统到Linux内核深入
linux·运维·服务器·开发语言·网络·c++·后端
计算机安禾15 分钟前
【c++面向对象编程】第6篇:this指针:对象如何知道自己在调用谁?
开发语言·c++
2301_8152795216 分钟前
如何实现C++ Web 自动化测试实战:常用函数全解析与场景化应用指南
开发语言·前端·c++
WL_Aurora20 分钟前
备战蓝桥杯国赛【Day 9】
python·算法·蓝桥杯