229. Majority Element II
生活随笔
收集整理的這篇文章主要介紹了
229. Majority Element II
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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
轉載于:https://www.cnblogs.com/ffeng0312/p/9227163.html
總結
以上是生活随笔為你收集整理的229. Majority Element II的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 洛谷P1057传球游戏题解
- 下一篇: 使用layui框架时,在input文本框