Single Number III - Implementation

Here is the implementation:

function singleNumber(nums):
    xorAll = 0
    for num in nums:
        xorAll = xorAll XOR num

    // xorAll = a XOR b
    // Find rightmost set bit
    rightmostBit = xorAll & (-xorAll)

    a = 0, b = 0
    for num in nums:
        if (num & rightmostBit) != 0:
            a = a XOR num
        else:
            b = b XOR num

    return [a, b]

O(n)O(n) time, O(1)O(1) space (excluding input). Two passes through the array.