3 line python solution O(n)

amazon
Tags: #<Tag:0x00007f242074ce80>

#1

class Solution:
# @param A : tuple of integers
# @return an integer
def majorityElement(self, A):
for i in A:
if A.count(i)>len(A)//2:
return i


#2

How is it O(n)? Worst case would be O(n/2*n) ie O(n^2).