当前位置:网站首页>229. Find mode II
229. Find mode II
2022-04-23 04:32:00 【Zhang Joshua】
229. Find mode II
- Question no : Power button 229
- Knowledge point : Count , Hash , Array
- Goal completion :21/150
- summary
stem :
Ideas :
- 1. Construct hash table through Dictionary ,
cnt={key:value, ...}
, Using the values in the array as the dictionary key, Take the number of occurrences of the value in the array as the number of occurrences of the dictionary value - 2. Traversal array , Store the elements in the array and the number of occurrences of the elements in the dictionary
cnt
in - 3. Find in dictionary
value
Greater thann//3
Ofkey
class Solution:
def majorityElement(self, nums: List[int]) -> List[int]:
cnt = {
}
ans = []
for v in nums:
if v in cnt:
cnt[v] += 1
else:
cnt[v] = 1
for key in cnt.keys():
if cnt[key] > (len(nums) // 3):
ans.append(key)
return ans
版权声明
本文为[Zhang Joshua]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230415046473.html
边栏推荐
- Inverse system of RC low pass filter
- VHDL语言实现32位二进制数转BCD码
- How to regulate intestinal flora? Introduction to common natural substances, probiotics and prebiotics
- 【测绘程序设计】坐标方位角推算神器(C#版)
- MYSQL去重方法汇总
- 【Echart】echart 入门
- zynq平臺交叉編譯器的安裝
- 2019 is coming to an end, the longest day.
- 2020 is coming to an end, special and unforgettable.
- 補:注解(Annotation)
猜你喜欢
[BIM introduction practice] wall hierarchy and FAQ in Revit
减治思想——二分查找详细总结
Thought of reducing Governance -- detailed summary of binary search
Brushless motor drive scheme based on Infineon MCU GTM module
Gut liver axis: host microbiota interaction affects hepatocarcinogenesis
Use recyclerview to realize left-right side-by-side classification selection
As a code farmer, what kind of experience is it that a girlfriend can code better than herself?
Introduction to Cortex-M3 register set, assembly language and C language interface
Common string processing functions in C language
Express中间件②(中间件的分类)
随机推荐
TreeSet after class exercises
A new method for evaluating the quality of metagenome assembly - magista
[AI vision · quick review of NLP natural language processing papers today, issue 31] Fri, 15 APR 2022
【论文阅读】【3d目标检测】Voxel Transformer for 3D Object Detection
Leetcode->1 两数之和
The perfect combination of collaborative process and multi process
HMS Core Discovery第14期回顾长文|纵享丝滑剪辑,释放视频创作力
重剑无锋,大巧不工
Alibaba cloud IOT transfer to PostgreSQL database scheme
单片机串口数据处理(2)——uCOSIII+循环队列接收数据
【Echart】echart 入門
UDP protocol and TCP protocol
Stm32f4 MCU ADC sampling and FFT of ARM-DSP Library
How to regulate intestinal flora? Introduction to common natural substances, probiotics and prebiotics
MySQL 2013 lost connection to MySQL server during query
单极性非归零NRZ码、双极性非归零NRZ码、2ASK、2FSK、2PSK、2DPSK及MATLAB仿真
win10, mysql-8.0.26-winx64.zip 安装
【BIM+GIS】ArcGIS Pro2. 8 how to open Revit model, Bim and GIS integration?
Chlamydia infection -- causes, symptoms, treatment and Prevention
[AI vision · quick review of NLP natural language processing papers today, No. 32] wed, 20 APR 2022