You are given an integer array nums in which every value occurs exactly twice, except for one value that occurs only once. Return the value that has no partner.
Aim for a solution that reads the array in a single pass of O(n) time and keeps only O(1) extra memory: no set, no map, no sorted copy.
9 and 0 each show up twice. -4 shows up once, and the pairs may be scattered anywhere in the array.
A one-element array has nothing to pair with, so its only value is the answer.
Constraints
1 <= nums.length <= 3 * 10⁴ (always odd)-3 * 10⁴ <= nums[i] <= 3 * 10⁴Think of an operation where a value combined with itself cancels to nothing, and where the order you combine things in makes no difference. Run it across the whole array and every pair disappears.
3