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;
    }
};
相关推荐
星马梦缘14 分钟前
死锁与进程资源分配问题的解法
算法·操作系统·深度优先·死锁
爱炼丹的James19 分钟前
第四章 数学知识
算法
吃好睡好便好27 分钟前
矩阵旋转的计算
学习·线性代数·算法·矩阵
袋鼠云数栈1 小时前
数栈 V7.0 多模态数据智能平台:打造 AI-Ready 的企业数据底座
大数据·数据结构·数据库·人工智能·数据治理·多模态
basketball6161 小时前
设计模式入门:2. 工厂模式详解 C++实现
开发语言·c++·设计模式
Lumbrologist1 小时前
【C++】零基础入门 · 第 16 节:智能指针
开发语言·c++
前进吧-程序员1 小时前
CRTP 与静态多态:不用虚函数也能多态
c++
basketball6161 小时前
设计模式入门:1. 单例模式详解 C++实现
c++·单例模式·设计模式
埃菲尔铁塔_CV算法1 小时前
基于扩张卷积与双分支参数调控的低光照图像增强算法完整研究与工程解析
人工智能·神经网络·算法·机器学习·计算机视觉
迈巴赫车主1 小时前
优先队列(PriorityQueue)
数据结构·算法