class Solution():
def morethanhalf(self,A):
count = 1
ans = A[0]
for i in range(len(A)-1):
if count == 0:
count = 1
ans = A[i+1]
if A[i] == A[i+1]:
count+=1
else:
count-=1
return ans
s = Solution()
print(s.morethanhalf([1,2,3,2,2,2,5,3,2]))
网友评论