Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.

You may assume that the array is non-empty and the majority element always exist in the array.

Example 1:

Input: [3,2,3]
Output: 3

Example 2:

Input: [2,2,1,1,1,2,2]
Output: 2
def majorityElement(nums):candidate = Nonecount = 0for item in nums:if item == candidate:count+=1elif count > 0:count -= 1else:candidate,count = num,1return candidate

Leetcode - 169. Majority Element (多数投票问题)相关推荐

  1. [勇者闯LeetCode] 169. Majority Element

    [勇者闯LeetCode] 169. Majority Element Description Given an array of size n, find the majority element. ...

  2. [LeetCode] 169. Majority Element 多数元素

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  3. Leetcode 169 Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  4. leetcode 169. Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  5. [LeetCode]: 169: Majority Element

    题目: Given an array of size n, find the majority element. The majority element is the element that ap ...

  6. [swift] LeetCode 169. Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  7. LeetCode 169 Majority Element(Majority Voting Algorithm)

    Majority Element Given an array of size n, find the majority element. The majority element is the el ...

  8. leetcode讲解--169. Majority Element

    169. Majority Element Given an array of size n, find the majority element. The majority element is t ...

  9. LeetCode 229 : Majority Element II

    Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorit ...

最新文章

  1. WSL系列操作:安装,卸载
  2. 健康日志之口腔粘膜----7-13
  3. linux内存操作----kernel 3.5.X copy_from_user()和copy_to_user()
  4. 【UML 建模】UML建模语言入门 -- 静态图详解 类图 对象图 包图 静态图建模实战
  5. Debian For ARM Webmin Server
  6. 吴恩达机器学习学习笔记第四章:python的配置
  7. php excel导入数据库显示乱码,php修改excel表格数据库数据格式-使用phpexcel导入excel表格数据到MYSQL,乱码怎么解决...
  8. ifc文件解析java_IFC标准 IFCWALLSTANDARDCASE参数说明
  9. 机动目标跟踪——Singer模型
  10. 三星宣布首款 PCIe 5.0 企业级 SSD:PM1743,将于 2022 年推出
  11. 红linux系统,红帽子linux系统
  12. java xheditor 上传图片_xheditor上传图片的java实现
  13. qt开发资料下载网址
  14. 【唐诗学习】一、古诗概述
  15. Bluetooth core 5.0 Generic Access Profile ---------- 模式 - BR/EDR 物理传输(physical transport)
  16. 【mysql升级步骤】windows mysql版本升级 ,mysql 5.6 升级到5.7.27
  17. c语言strcat()/strcat_s()函数详解
  18. 管你 JDK 还是 Linux,我 Netty 稳坐钓鱼台
  19. 15分钟破解网站验证码
  20. 【breathandlife】气势磅礴、比较好听的旋律有哪些?

热门文章

  1. 通过rsync清除目录的shell脚本
  2. ORA-04031:oracle无法分配共享内存
  3. 《Adobe Illustrator大师班:经典作品与完美技巧赏析》—Bree Léman
  4. RedHat6.5 搭建glusterfs全过程
  5. 思科谈OpenDaylight
  6. fzu 2139 久违的月赛之二
  7. pku3020 Antenna Placement (解法1)
  8. 擷取Registry內的螢幕EDID資訊(沒解決問題不過可以學下)
  9. 编译乱序(Compiler Reordering)
  10. 不抓包,如何学得了 TCP