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;
    }
};
相关推荐
luckycoding几秒前
42. 接雨水
leetcode
天赐学c语言1 分钟前
Linux - windows作为client访问linux服务端
linux·网络·c++
We་ct2 分钟前
LeetCode 39. 组合总和:DFS回溯解法详解
前端·算法·leetcode·typescript·深度优先·个人开发·回溯
小杍随笔3 分钟前
【Rust中所有符号的作用及使用场景详解】
java·算法·rust
MicroTech20258 分钟前
微算法科技(NASDAQ: MLGO)探索量子机器学习算法在预测模型中的应用,利用量子核方法提升复杂模式识别能力
科技·算法·机器学习
absunique1 小时前
算法设计模式看编程思维的抽象能力的技术6
算法·设计模式
DeepModel2 小时前
【概率分布】Beta分布详解
算法·概率论
我命由我123452 小时前
React - 验证 Diffing 算法、key 的作用
javascript·算法·react.js·前端框架·html·html5·js
Anastasiozzzz6 小时前
深入研究Redis的ZSet底层数据结构:从 Ziplist 的级联更新到 Listpack 的完美救场
数据结构·数据库·redis
70asunflower6 小时前
CUDA编程指南基础知识点总结(5)
c++·人工智能·cuda