Python | Leetcode Python题解之第229题多数元素II

题目:

题解:

python 复制代码
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 item in cnt.keys():
            if cnt[item] > len(nums)//3:
                ans.append(item)

        return ans
相关推荐
数学人学c语言1 小时前
记录torch运行的bug
python·深度学习·bug
小爬虫程序猿1 小时前
使用Python爬虫获取淘宝商品详情:API返回值说明与案例指南
开发语言·爬虫·python
ONE_PUNCH_Ge1 小时前
Python selenium 库
python
阳光男孩011 小时前
力扣2382. 删除操作后的最大子段和
算法·leetcode
m0_748240021 小时前
Python大数据可视化:基于大数据技术的共享单车数据分析与辅助管理系统_flask+hadoop+spider
大数据·python·信息可视化
放氮气的蜗牛2 小时前
Python爬虫系列教程之第十五篇:爬取电商网站商品信息与数据分析
爬虫·python·数据分析
阿正的梦工坊2 小时前
PyTorch torch.logsumexp 详解:数学原理、应用场景与性能优化(中英双语)
人工智能·pytorch·python
奔跑吧邓邓子2 小时前
【Python爬虫(63)】从0到1:打造图片与视频爬虫攻略
开发语言·爬虫·python·视频·图片
m0_748251082 小时前
Elasticsearch(ES)基础查询语法的使用
python·elasticsearch·django
火龙谷3 小时前
Windows 下 Visual Studio Code 常用快捷键指南
python