leetcode 225 Implement Stack using Queues

Dora ·
更新时间:2024-09-20
· 846 次阅读

leetcode 225 Implement Stack using Queues

leetcode 2020年3月 每日一题打卡

思路: python

细节:

查找list中某元素的位置: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

如转载请标明出处!侵权必究


作者:萝卜upupup



stack leetcode USING

需要 登录 后方可回复, 如果你还没有账号请 注册新账号