当前位置:网站首页>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))

边栏推荐
- Defect detection - Halcon surface scratch detection
- Poj3414 extensive search
- AD637使用笔记
- Common interview questions of JVM manufacturers
- The American Championship is about to start. Are you ready?
- Create a virtual machine on VMware (system not installed)
- Recovery technology with checkpoints
- Pl/sql basic syntax
- Net small and medium-sized enterprise project development framework series (one)
- How to add new fields to mongodb with code (all)
猜你喜欢

总结出现2xx、3xx、4xx、5xx状态码的原因

每日刷题记录 (十四)

Shell script, awk condition judgment and logic comparison &||

Summary of concurrency control

Oracle checkpoint queue - Analysis of the principle of instance crash recovery

Business learning of mall commodity module

Stored procedures and stored functions

Huawei cloud modelarts text classification - takeout comments

The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!

The real situation of programmers
随机推荐
The real situation of programmers
Cross end solutions to improve development efficiency
C language knowledge points link
每日刷题记录 (十四)
PyGame practical project: write Snake games with 300 lines of code
Codeforces 12D Ball 树形阵列模拟3排序元素
Summary of El and JSTL precautions
Shell script, awk condition judgment and logic comparison &||
Database recovery strategy
Codeforces 12D ball tree array simulation 3 sorting elements
数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖
HDU 4391 paint the wall segment tree (water
Meituan dynamic thread pool practice ideas, open source
Business learning of mall commodity module
Daily question brushing record (XIV)
AD637 usage notes
Poj 3237 Tree (Tree Chain Split)
regular expression
华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
Detailed explanation of memset() function usage