Bit Manipulation XOR tricks
113. Single Number III
You are given an array of integers nums. Exactly two values in it appear only once. Every other value
appears exactly twice. Return the two values that appear once.
You may return the two values in either order. The examples show them in ascending order, which is how the judge compares them.
Example 1
Input: nums = [3, 10, 5, 3, 6, 5]
[6,10]Explanation: 3 appears at indexes 0 and 3, and 5 at indexes 2 and 5. The values 6 and 10 appear once each.
Example 2
Input: nums = [7, 2]
[2,7]Explanation: Both values appear once. Returning [7,2] is accepted too.
Example 3
Input: nums = [2147483647, 9, -2147483648, 9]
[-2147483648,2147483647]Explanation: 9 appears twice. The largest and the smallest 32-bit integers appear once each.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
2 ≤ nums.length ≤ 105-231 ≤ nums[i] ≤ 231 − 1- Exactly two values appear once, and every other value appears exactly twice.
Clarifying questions
What you would ask an interviewer before writing any code.