当前位置: 首页 > news >正文

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

二、题解

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;}
};
http://www.lryc.cn/news/212428.html

相关文章:

  • 学习笔记---更进一步的双向链表专题~~
  • vscode格式化代码, 谷歌风格, 允许短if同行短块同行, tab = 4舒适风格
  • 百度富文本上传图片后样式崩塌
  • autoware.ai中检测模块lidar_detector caffe
  • CentOS安装Ruby环境
  • 力扣第509题 斐波那契数 新手动态规划(推荐参考) c++
  • canvas绘制签名并保存
  • Android渲染流程
  • 牛客-【237题】算法基础精选题单-第二章 递归、分治
  • leetcode-字符串
  • 多线程---synchronized特性+原理
  • Qt实现卡牌对对碰游戏
  • 【3D 图像分割】基于 Pytorch 的 VNet 3D 图像分割7(数据预处理)
  • 极米科技H6 Pro 4K、H6 4K高亮定焦版——开启家用投影4K普及时代
  • 软考系统架构师知识点集锦九:数据库系统
  • IOC课程整理-6 Spring IoC 依赖注入
  • FANUC机器人PRIO-621和PRIO-622设备和控制器没有运行故障处理
  • 《动手深度学习》线性回归简洁实现实例
  • 国家数据局正式揭牌,数据专业融合型人才迎来发展良机
  • 基于springboot实现休闲娱乐代理售票平台系统项目【项目源码+论文说明】
  • 3.AUTOSAR OS分析(一)
  • AB试验(七)利用Python模拟A/B试验
  • Go语言入门-流程控制语句
  • 深入探究ASEMI肖特基二极管MBR60100PT的材质
  • python类模拟“对战游戏”
  • Maven第二章:Maven基本概念与生命周期
  • <蓝桥杯软件赛>零基础备赛20周--第3周--填空题
  • 【Linux】VM及WindowsServer安装
  • 【实用教程】MySQL内置函数
  • 第十二节——ref