leetcode 225 Implement Stack using Queues queue stack

leetcode 225 Implement Stack using Queues queue stack

leetcode 2020 March 1 question daily punch

Ideas: Python

detail:

  1. Find a list of elements in a position: list.index (i)
  2. Rounding down: int ()

Code:

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

        

As reproduced, please indicate the source! All Rights Reserved

Published 20 original articles · won praise 1 · views 209

Guess you like

Origin blog.csdn.net/weixin_43973433/article/details/104846878