Problem :

https://leetcode.com/problems/single-number/description/


My Solution :

class Solution:
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
ans = 0
for n in nums:
ans ^= n
return ans


Comment :

xor의 아래 2가지 성질을 이용해 풀었다.

n ^ 0 = n

n ^ n = 0