class Solution:
def MoreThanHalfNum_Solution(self, numbers):
# write code here
if not numbers:
return 0
count = 0
value = None
for i in numbers:
if value == None and count == 0:
value = i
count += 1
if value != None and count > 0:
if value == i:
count += 1
else:
count -= 1
if count == 0:
value = None
count2 = 0
if value:
for i in numbers:
if i == value:
count2 += 1
if 2*count2 > len(numbers):
return value
else:
return 0
网友评论