z =0,对list中的逐个数使用count()函数计数,并与len(list)/2进行比较,只要超过就用数替换z,一个list只有一个可以满足的数,所有只要有满足的z就等于那个数,如果list里的数都不满足则z依然等于0.
def MoreThanHalfNum_Solution(self, numbers):
# write code here
a = len(numbers)
x =[]
z = 0
for i in range(a):
y = numbers.count(numbers[i])
if y > a/2:
z = numbers[i]
return z