136. Number only show once
- tags
- trick, BinaryOperation
- source
- leetcode-cn
Edge Cases
Solution - O(N) Space
- use set, when number in set, delete it; not in set, add it.
after one iteration, left is the number only shows once
- hashset, store number showing times
- set store all numbers, get sum1 from set, sum1 * 2 - sum(array) = answer
Complexity
Solution - BinaryOperation
a xor 0 = a
a xor a = 0
a xor b xor c = a xor c xor b = a xor (c xor b)
iterate whole array, xor every item, left is answer
Complexity