Python | Leetcode Python题解之第169题多数元素

题目:

题解:

python 复制代码
class Solution:
    def majorityElement(self, nums: List[int]) -> int:
        count = 0
        candidate = None

        for num in nums:
            if count == 0:
                candidate = num
            count += (1 if num == candidate else -1)

        return candidate
相关推荐
无语的小歪歪3 分钟前
ATF 智测 1.0
python·测试工具·集成测试
czq_26867194878 分钟前
Python打卡第45天
开发语言·python
java_prinln10 分钟前
9. Agent 的长短期记忆系统怎么做的?记忆是怎么存的?粒度是多少?怎么用的?
数据库·python·agent
FOAF-lambda15 分钟前
Python实战:基于OpenCV与单调栈,精准定位PDF中最大的空白区域
python·opencv·pdf
terry60020 分钟前
企业数据查询接口防爬实战:图形验证码服务端校验接入与限流设计(附Python)
python·信息与通信·图形验证码·反爬虫·人机验证·行为验证码·滑动拼图验证
量化炼金 (CodeAlchemy)21 分钟前
【Python】pandas vs polars 简单性能对比测试
开发语言·python·pandas
学习论之费曼学习法23 分钟前
无人值守AI内容矩阵实战(7):Playwright 发布器避坑——编辑器竞态、索引延迟与风控
python·线性代数·矩阵·编辑器·浏览器自动化·playwright·踩坑记录
wuyk55529 分钟前
PyQt6-第06讲-主窗口框架
python·pyqt
ss.li30 分钟前
rppg相关论文阅读笔记10.22
论文阅读·笔记·python
tryCbest31 分钟前
Python之Flask项目部署到阿里云
python·阿里云·flask