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;
    }
};
相关推荐
紫陌涵光13 小时前
54. 替换数字(第八期模拟笔试)
数据结构·c++·算法
TracyCoder12313 小时前
LeetCode Hot100(53/100)——739. 每日温度
算法·leetcode·职场和发展
_Twink1e13 小时前
[算法竞赛]二、链表
数据结构·算法·链表
民乐团扒谱机13 小时前
【读论文】引力与惯性的起源:从全息原理到牛顿定律与爱因斯坦方程
算法·量子力学··万有引力·爱因斯坦方程·全息原理·牛顿定律
努力学算法的蒟蒻13 小时前
day84(2.13)——leetcode面试经典150
算法·leetcode·面试
@––––––13 小时前
力扣hot100—系列8-回溯算法
javascript·算法·leetcode
!停13 小时前
数据结构二叉树—堆(2)&链式结构(上)
数据结构·算法
C++ 老炮儿的技术栈13 小时前
万物皆文件:Linux 抽象哲学的开发之美
c语言·开发语言·c++·qt·算法
im_AMBER13 小时前
Leetcode 120 求根节点到叶节点数字之和 | 完全二叉树的节点个数
数据结构·学习·算法·leetcode·二叉树·深度优先
1027lonikitave13 小时前
FFTW的expr.ml怎么起作用
算法·哈希算法