Two Lonely Numbers
In nums, exactly two values appear once and all others appear twice. Return the two values in ascending order.
Requirements
- time and space with XOR.
Examples
EXAMPLE WALKTHROUGHclassic
A guided view of the published example, not a trace of your code.
INPUT
[[1,2,1,3,2,5]]TASKtwo_lonely_numbers()
EXPECTED OUTPUT
[3,5]Start with the input values shown in this example.
Example 1 of 3
Input: nums = [1,2,1,3,2,5]
Output: [3,5]
Explanation: classic
Input: nums = [-1,0]
Output: [-1,0]
Explanation: negative
Input: nums = [0,1]
Output: [0,1]
Explanation: two values
Hint 1
XOR everything to get a ^ b.
Hint 2
Any set bit of a ^ b splits the numbers into two groups, each containing one lonely number.