```
def majorityElement(self, nums):
if len(nums)==1 or len(nums)==2:
return nums[0]
else:
l=sorted(nums)
x=l[:len(nums)/2+1]
y=l[len(nums)/2+1:]
a=set(x)
b=set(y)
if len(a)==1:
return x[0]
else:
return y[0]
```