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;
    }
};
相关推荐
xu_yule2 小时前
算法基础-路径类dp
算法
智驱力人工智能2 小时前
从项目管理视角 拆解景区无人机人群密度分析系统的构建逻辑 无人机人员密度检测 无人机人群密度检测系统价格 低空人群密度统计AI优化方案
人工智能·深度学习·算法·安全·无人机·边缘计算
历程里程碑2 小时前
C++ 4:内存管理
java·c语言·开发语言·数据结构·c++·笔记·算法
The Last.H2 小时前
Codeforces Round 1069 (Div. 2)
算法
LYFlied2 小时前
【每日算法】LeetCode 76. 最小覆盖子串
数据结构·算法·leetcode·面试·职场和发展
LXS_3573 小时前
Day17 C++提高 之 类模板案例
开发语言·c++·笔记·算法·学习方法
2301_789015623 小时前
C++:多态(面向对象的主要手段之一)
c语言·开发语言·c++·多态
小年糕是糕手3 小时前
【C++】string类(一)
linux·开发语言·数据结构·c++·算法·leetcode·改行学it
初願致夕霞3 小时前
LeetCode双指针题型总结
算法·leetcode·职场和发展
努力学算法的蒟蒻3 小时前
day36(12.17)——leetcode面试经典150
算法·leetcode·面试