136. Single Number
Easy
Problem:
Input: nums = [2,2,1]
Output: 1What to learn:
Exclusive OR (XOR)
>>> 0 ^ 0
0
>>> 4 ^ 0
4
>>> 4 ^ 4
0Solution:
Last updated
class Solution:
def singleNumber(self, nums: List[int]) -> int:
result = 0
for num in nums:
result ^= num
print(result)
return result