# -*- coding:utf-8 -*- class Gift: def getValue(self, gifts, n): # write code here count=1 candidate=gifts[0] for i in gifts[1:]:#从第二个元素开始 if i==candidate: count+=1 elif count==0: candidate=i count=0 else: count-=1 count=0 for i in gifts: if i==candidate: count+=1 if count>n/2: return candidate return 0