当前位置:网站首页>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
边栏推荐
- 秒杀所有区间相关问题
- [BIM introduction practice] wall hierarchy and FAQ in Revit
- [AI vision · quick review of robot papers today, issue 31] Fri, 15 APR 2022
- Does China Mobile earn 285 million a day? In fact, 5g is difficult to bring more profits, so where is the money?
- [AI vision · quick review of NLP natural language processing papers today, issue 28] wed, 1 Dec 2021
- 上海航芯技术分享 | ACM32 MCU安全特性概述
- Why recommend you to study embedded
- Cause analysis of incorrect time of AI traffic statistics of Dahua Equipment Development Bank
- 为什么推荐你学嵌入式
- 【李宏毅2022 机器学习春】hw6_GAN(不懂..)
猜你喜欢

STM32F4单片机ADC采样及ARM-DSP库的FFT

Hard core chip removal

秒杀所有区间相关问题

Overview of knowledge map (II)

减治思想——二分查找详细总结

Retrieval question answering system baseline

Xiaomi, which has set the highest sales record of domestic mobile phones in overseas markets, paid renewed attention to the domestic market

Second kill all interval related problems
![[AI vision · quick review of robot papers today, issue 32] wed, 20 APR 2022](/img/eb/916a3fc1a89356fd8e74b943172ac3.png)
[AI vision · quick review of robot papers today, issue 32] wed, 20 APR 2022

Does China Mobile earn 285 million a day? In fact, 5g is difficult to bring more profits, so where is the money?
随机推荐
CRF based medical entity recognition baseline
RuntimeError: output with shape [4, 1, 512, 512] doesn‘t match the broadcast shape[4, 4, 512, 512]
UDP协议与TCP协议
[AI vision · quick review of NLP natural language processing papers today, issue 30] Thu, 14 APR 2022
Basic introduction to spot gold
【Echart】echart 入門
php导出Excel表格
Go 语言中的 logger 和 zap 日志库
io.Platform.packageRoot; // ignore: deprecated_member_use
Writing latex with vscode - the latest tutorial 2022 / 4 / 17
[latex] differences in the way scores are written
Nel ASA:挪威Herøya设施正式启用
MYSQL去重方法汇总
Effects of antibiotics on microbiome and human health
C language character constant
Cuda11 is installed perfectly in win10 X + pytorch 1.9 (blood flowing into the river) cuda. is_ Available() becomes true!
The latest price trend chart and trading points of London Silver
Mysql出现2013 Lost connection to MySQL server during query
网络原理 | TCP/IP中的连接管理机制 重要协议与核心机制
The whole process of connecting the newly created unbutu system virtual machine with xshell and xftp