当前位置:网站首页>Unique occurrence times of leetcode simple questions
Unique occurrence times of leetcode simple questions
2022-07-05 22:03:00 【·Starry Sea】
subject
Give you an array of integers arr, Please help count the number of occurrences of each number in the array .
If the number of occurrences of each number is unique , Just go back to true; Otherwise return to false.
Example 1:
Input :arr = [1,2,2,1,1,3]
Output :true
explain : In this array ,1 There is 3 Time ,2 There is 2 Time ,3 Only appeared. 1 Time . No two numbers appear the same number .
Example 2:
Input :arr = [1,2]
Output :false
Example 3:
Input :arr = [-3,0,1,-3,1,1,1,-3,10,0]
Output :true
Tips :
1 <= arr.length <= 1000
-1000 <= arr[i] <= 1000
source : Power button (LeetCode)
Their thinking
First, count the frequency of elements , Then the frequency is de duplicated , If there is no change after weight removal , Then the number of occurrences is unique .
class Solution:
def uniqueOccurrences(self, arr: List[int]) -> bool:
return len(set(Counter(arr).values()))==len(Counter(arr))
边栏推荐
- Win11运行cmd提示“请求的操作需要提升”的解决方法
- MySQL disconnection reports an error MySQL ldb_ exceptions. OperationalError 4031, The client was disconnected by the server
- 了解 Android Kotlin 中 DataStore 的基本概念以及为什么应该停止在 Android 中使用 SharedPreferences
- [Yugong series] go teaching course 003-ide installation and basic use in July 2022
- The simple problem of leetcode is to split a string into several groups of length K
- Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
- 多家呼吸机巨头产品近期被一级召回 呼吸机市场仍在增量竞争
- Oracle advanced query
- 装饰器学习01
- Server optimization of performance tuning methodology
猜你喜欢
Storage optimization of performance tuning methodology
PIP install beatifulsoup4 installation failed
K210学习笔记(四) K210同时运行多个模型
Index optimization of performance tuning methodology
Deeply convinced plan X - network protocol basic DNS
AD637使用筆記
华为游戏多媒体服务调用屏蔽指定玩家语音方法,返回错误码3010
Implementation technology of recovery
Drawing HSV color wheel with MATLAB
MMAP学习
随机推荐
Did you brush the real title of the blue bridge cup over the years? Come here and teach you to counter attack!
Meituan dynamic thread pool practice ideas, open source
数据泄露怎么办?'华生·K'7招消灭安全威胁
datagrid直接编辑保存“设计缺陷”
How to use tensorflow2 for cat and dog classification and recognition
Huawei cloud modelarts text classification - takeout comments
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
Huawei fast game failed to call the login interface, and returned error code -1
Matlab | app designer · I used Matlab to make a real-time editor of latex formula
Image editor for their AutoLayout environment
大约SQL现场“这包括”与“包括在”字符串的写法
Blocking of concurrency control
了解 Android Kotlin 中 DataStore 的基本概念以及为什么应该停止在 Android 中使用 SharedPreferences
CRM creates its own custom report based on fetch
How to organize an actual attack and defense drill
如何组织一场实战攻防演练
The simple problem of leetcode is to split a string into several groups of length K
Database tuning solution
如何向mongoDB中添加新的字段附代码(全)
Poj 3237 Tree (Tree Chain Split)