Implementar leetcode 225 Pila pila utilizando colas de colas
leetcode 2020 1 pregunta de marzo de golpe diaria
Ideas: Python
detalles:
- Encuentra una lista de elementos en una posición: list.index (i)
- Redondeo a la baja: int ()
código:
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
Como reproduce, por favor indique la fuente! Reservados todos los derechos