首页 > 其他 > 详细

169. Majority Element

时间:2018-06-26 10:28:35      阅读:200      评论:0      收藏:0      [点我收藏+]

class Solution(object):
  def majorityElement(self, nums):
  """
  :type nums: List[int]
  :rtype: int
  """
  n=len(nums)
  a=n/2
  if n>=2:
    freq={}
    for i in nums:
      if i not in freq:
        freq[i]=1
      else:
        freq[i] +=1
        if freq[i]>a:
          return i
  else:
    return nums[0]

169. Majority Element

原文:https://www.cnblogs.com/ffeng0312/p/9227162.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!