Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. You must implement a solution with a linear runtime complexity and use only constant extra space.
Example 1
Input: nums = [4,1,2,1,2]
Output: 4
Explanation: 1 and 2 each appear twice, and 4 appears once, so the answer is 4.
Example 2
Input: nums = [2,2,1]
Output: 1
Explanation: 2 appears twice and 1 appears once.
Example 3
Input: nums = [1]
Output: 1
Explanation: The only element appears once.
XOR of a number with itself is 0, and XOR with 0 leaves a number unchanged. XOR every element together: all the paired numbers cancel to 0 and only the unique element remains.
Run checks all cases above. Submit evaluates all test cases.