Single line solution using set

def singleNumber(self, A):
     return sum(set(A))*2-sum(A)


Can you explain the logic?


Every element is repeated twice except one so if we take set of A it has all unique numbers only. Therefore twice the sum of set(A) - sum of A will give that number which is not repeated.