Bit Manipulation XOR tricks
110. Single Number
You are given an array of integers nums. Every value in it appears exactly twice, except one value, which
appears only once. Return the value that appears once.
The two copies of a value can be anywhere in the array. They do not have to be next to each other.
Example 1
Input: nums = [4, -9, 13, 4, 0, 13, 0]
-9Explanation: 4 appears at indexes 0 and 3, 13 at indexes 2 and 5, and 0 at indexes 4 and 6. Only -9 appears once.
Example 2
Input: nums = [6, 6, 0]
0Explanation: 6 appears twice, so the answer is 0.
Example 3
Input: nums = [-2147483648, 2147483647, -2147483648]
2147483647Explanation: The smallest 32-bit integer appears at both ends of the array. The largest one appears once, between them.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ nums.length ≤ 105-231 ≤ nums[i] ≤ 231 − 1- Every value appears exactly twice, except one value, which appears once.
Clarifying questions
What you would ask an interviewer before writing any code.