leetcode 225は、キューキュースタックを使用してスタックを実装します
leetcode 2020 3月1日、質問、毎日パンチ
アイデア:パイソン
詳細:
- 位置にある要素のリストを表示して下さい:list.index(I)
- ダウン丸め:int型()
コード:
class Solution(object):
def majorityElement(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
tag=[]
times=[]
id_tag=0
for i in nums:
if i in tag:
times[tag.index(i)]+=1
else:
tag.append(i)
times.append(1)
id_tag+=1
s=int(len(nums)/2)
ans=0
best=0
for i in range(0,id_tag):
if times[i]>best and times[i]>s:
ans=tag[i]
best=times[i]
return ans
再現したように、ソースを明記してください!すべての権利予約