[
bit manipulation
hash table
]
Leetcode 0136 Single Number
Problem statement
https://leetcode.com/problems/single-number/
Solution
There is straightforward hash-table solution with O(n) memory and time. We can also use bit manipulation trick to evaluate XOR of all numbers, which is what we need.
Complexity
Time is O(n), space is O(1).
Code
class Solution:
def singleNumber(self, nums):
return reduce(xor, nums)