当前位置:网站首页>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
边栏推荐
- matlab讀取多張fig圖然後合並為一張圖(子圖的形式)
- 电钻、电锤、电镐的区别
- Set classic topics
- io.Platform.packageRoot; // ignore: deprecated_member_use
- The latest price trend chart and trading points of London Silver
- Operating skills of spot gold_ Wave estimation curve
- IEEE Transactions on Industrial Informatics(TII)投稿须知
- 第四章 --- 了解标准设备文件、过滤器和管道
- UDP protocol and TCP protocol
- Xiaohongshu was exposed to layoffs of 20% as a whole, and the internal volume among large factories was also very serious
猜你喜欢
小红书被曝整体裁员20%,大厂之间内卷也很严重
Express中间件①(中间件的使用)
How to regulate intestinal flora? Introduction to common natural substances, probiotics and prebiotics
[echart] Introduction to echart
Matlab reads multiple fig graphs and then combines them into one graph (in the form of sub graph)
520.检测大写字母
STM32单片机ADC规则组多通道转换-DMA模式
Apache Bench(ab 压力测试工具)的安装与使用
Understand the gut organ axis, good gut and good health
Microbial neuroimmune axis -- the hope of prevention and treatment of cardiovascular diseases
随机推荐
无线键盘全国产化电子元件推荐方案
A new method for evaluating the quality of metagenome assembly - magista
Set经典小题目
为什么推荐你学嵌入式
Jetpack 之 LifeCycle 组件使用详解
Leetcode->1 两数之和
IDE Idea 自动编译 与 On Upate Action 、 On Frame Deactivation 的配置
C语言 字符常量
AWS EKS 部署要点以及控制台与eksctl创建的差异
SQL statement for adding columns in MySQL table
【论文阅读】【3d目标检测】Improving 3D Object Detection with Channel-wise Transformer
Mysql---数据读写分离、多实例
補:注解(Annotation)
Fusobacterium -- symbiotic bacteria, opportunistic bacteria, oncobacterium
Bridge between ischemic stroke and intestinal flora: short chain fatty acids
第四章 --- 了解标准设备文件、过滤器和管道
兼容NSR20F30NXT5G的小体积肖特基二极管
IEEE Transactions on Industrial Informatics(TII)投稿须知
Xiaohongshu was exposed to layoffs of 20% as a whole, and the internal volume among large factories was also very serious
Chapter 4 - understanding standard equipment documents, filters and pipelines