class Solution(object): def singleNumber(self, nums): # https://leetcode.com/discuss/48119/single-number-iii 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]
Could you please explain the steps in your program? It's pretty confusing. I worked out some examples, still couldn't get how you arrived at the solution.
The idea is exactly the same as here:
xor = xor & (xor - 1) ^ xor
is to keep the lowest set bit only in xor.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.