首页 > 其他 > 详细

229. Majority Element II

时间:2018-06-26 10:36:07      阅读:219      评论:0      收藏:0      [点我收藏+]

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

229. Majority Element II

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

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