当前位置:网站首页>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))
边栏推荐
- Database recovery strategy
- Database tuning solution
- An exception occurred in Huawei game multimedia calling the room switching method internal system error Reason:90000017
- 大约SQL现场“这包括”与“包括在”字符串的写法
- Talking about MySQL index
- Detailed explanation of memset() function usage
- EL与JSTL注意事项汇总
- 数据泄露怎么办?'华生·K'7招消灭安全威胁
- Recovery technology with checkpoints
- 从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
猜你喜欢
Meituan dynamic thread pool practice ideas, open source
Overview of database recovery
数据泄露怎么办?'华生·K'7招消灭安全威胁
EBS Oracle 11g cloning steps (single node)
元宇宙中的三大“派系”
Huawei game multimedia service calls the method of shielding the voice of the specified player, and the error code 3010 is returned
Blocking of concurrency control
How to view Apache log4j 2 remote code execution vulnerability?
ICMP 介绍
Oracle checkpoint queue - Analysis of the principle of instance crash recovery
随机推荐
CRM creates its own custom report based on fetch
Defect detection - Halcon surface scratch detection
Interview questions for basic software testing
A long's perception
大约SQL现场“这包括”与“包括在”字符串的写法
Server optimization of performance tuning methodology
Installation of VMware Workstation
Analysis and test of ModbusRTU communication protocol
QML reported an error expected token ";", expected a qualified name ID
Pl/sql basic syntax
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
初级软件测试必问面试题
Win11运行cmd提示“请求的操作需要提升”的解决方法
Yolov5 training custom data set (pycharm ultra detailed version)
Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~
DataGrid directly edits and saves "design defects"
The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
Type of fault
Meituan dynamic thread pool practice ideas, open source
【愚公系列】2022年7月 Go教学课程 004-Go代码注释