当前位置:网站首页>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
cntin - 3. Find in dictionary
valueGreater thann//3Ofkey
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
边栏推荐
- [AI vision · quick review of robot papers today, issue 32] wed, 20 APR 2022
- 【Pytorch基础】torch.split()用法
- 2019 is coming to an end, the longest day.
- C语言:恶搞小游戏
- C语言: 指针的进阶
- 国外LEAD,联盟经理常见问答
- Summary of Android development posts I interviewed in those years (attached test questions + answer analysis)
- [AI vision · quick review of robot papers today, issue 31] Fri, 15 APR 2022
- Bacterial infection and antibiotic use
- Coinbase: basic knowledge, facts and statistics about cross chain bridge
猜你喜欢

【Echart】echart 入门

补:注解(Annotation)

阿里十年技术专家联合打造“最新”Jetpack Compose项目实战演练(附Demo)

洛谷P1858 【多人背包】 (背包求前k优解)
![[AI vision · quick review of robot papers today, issue 31] Fri, 15 APR 2022](/img/f5/3cd3abee1480dc2cefa7f35696631b.png)
[AI vision · quick review of robot papers today, issue 31] Fri, 15 APR 2022

Matlab reads multiple fig graphs and then combines them into one graph (in the form of sub graph)
![[AI vision · quick review of NLP natural language processing papers today, issue 31] Fri, 15 APR 2022](/img/40/72fdf9c89ed7d063cc368e6e052d0f.png)
[AI vision · quick review of NLP natural language processing papers today, issue 31] Fri, 15 APR 2022

383. 赎金信

无线充电全国产化电子元件推荐方案

协程与多进程的完美结合
随机推荐
LabVIEW 小端序和大端序区别
【测绘程序设计】坐标方位角推算神器(C#版)
QtSpim手册-中文翻译
Understand the gut organ axis, good gut and good health
zynq平台交叉编译器的安装
229. 求众数 II
As a code farmer, what kind of experience is it that a girlfriend can code better than herself?
上海航芯技术分享 | ACM32 MCU安全特性概述
[mapping program design] coordinate inverse artifact v1 0 (with C / C / VB source program)
matlab读取多张fig图然后合并为一张图(子图的形式)
顺序表的基本操作
MATLAB lit plusieurs diagrammes fig et les combine en un seul diagramme (sous forme de sous - Diagramme)
1个需求的一生,团队协作在云效钉钉小程序上可以这么玩
/etc/bash_completion.d目录作用(用户登录立刻执行该目录下脚本)
[AI vision · quick review of today's sound acoustic papers, issue 2] Fri, 15 APR 2022
Nel ASA: her ø Ya facility in Norway officially opened
zynq平臺交叉編譯器的安裝
Installation du compilateur croisé de la plateforme zynq
[BIM introduction practice] wall hierarchy and FAQ in Revit
Inverse system of RC low pass filter