class Solution(object):
def singleNumber(self, nums):
# https://leetcode.com/discuss/48119/singlenumberiii
xor = 0
for num in nums: xor ^= num
xor = xor & (xor  1) ^ xor
a = b = 0
for num in nums:
if xor & num:
a ^= num
else:
b ^= num
return [a, b]
Python O(n)  O(1) solution

The idea is exactly the same as here:
https://leetcode.com/discuss/60408/sharingexplanationofthesolutionxor = xor & (xor  1) ^ xor
is to keep the lowest set bit only in xor.