当前位置:网站首页>229. 求众数 II
229. 求众数 II
2022-04-23 04:15:00 【张.Joshua】
229. 求众数 II
- 题号:力扣229
- 知识点:计数,哈希,数组
- 目标完成度:21/150
- 总结
题干:

思路:
- 1.通过字典构造散列表,
cnt={key:value, ...},以数组中的值为字典的key,以数组中的值出现的次数为字典的value - 2.遍历数组,将数组中的元素和元素出现的次数存储在字典
cnt中 - 3.查找字典中
value值大于n//3的key
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
版权声明
本文为[张.Joshua]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_44742084/article/details/124355761
边栏推荐
- VSCode配置之Matlab极简配置
- MYSQL50道基础练习题
- VHDL implementation of 32-bit binary to BCD code
- Express middleware ② (classification of Middleware)
- AWS EKS添加集群用户或IAM角色
- 阿里云IoT流转到postgresql数据库方案
- 小红书被曝整体裁员20%,大厂之间内卷也很严重
- MATLAB lit plusieurs diagrammes fig et les combine en un seul diagramme (sous forme de sous - Diagramme)
- [Li Hongyi 2022 machine learning spring] hw6_ Gan (don't understand...)
- VHDL语言实现32位二进制数转BCD码
猜你喜欢

Qtspim manual - Chinese Translation

Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.

Add the compiled and installed Mysql to the path environment variable

Iron and intestinal flora

Common string processing functions in C language

A function second kill 2sum 3sum 4sum problem

Photoshop installation under win10

Machine translation baseline

【NeurIPS 2019】Self-Supervised Deep Learning on Point Clouds by Reconstructing Space

【ICCV 2019】MAP-VAE:Multi-Angle Point Cloud-VAE: Unsupervised Feature Learning for 3D Point Clouds..
随机推荐
C language character constant
[AI vision · quick review of today's sound acoustic papers, issue 2] Fri, 15 APR 2022
創下國產手機在海外市場銷量最高紀錄的小米,重新關注國內市場
Express middleware ② (classification of Middleware)
【BIM入门实战】Revit中的墙体层次以及常见问题解答
Leetcode->1 两数之和
阿里云IoT流转到postgresql数据库方案
Difference between LabVIEW small end sequence and large end sequence
QtSpim手册-中文翻译
MYSQL去重方法汇总
Express中间件①(中间件的使用)
Qtspim manual - Chinese Translation
一个函数秒杀2Sum 3Sum 4Sum问题
STM32上μC/Shell移植与应用
【论文阅读】【3d目标检测】point transformer
RuntimeError: output with shape [4, 1, 512, 512] doesn‘t match the broadcast shape[4, 4, 512, 512]
[AI vision · quick review of robot papers today, issue 31] Fri, 15 APR 2022
Stm32f4 MCU ADC sampling and FFT of ARM-DSP Library
Single chip microcomputer serial port data processing (2) -- ucosiii + cyclic queue receiving data
Nel ASA: her ø Ya facility in Norway officially opened