Lonely Number
Every element of nums appears exactly twice except one. Return that element.
Requirements
- time and extra space. XOR has the properties and .
Examples
EXAMPLE WALKTHROUGHsmall
A guided view of the published example, not a trace of your code.
INPUT
[[2,2,1]]TASKlonely_number()
EXPECTED OUTPUT
1Start with the input values shown in this example.
Example 1 of 3
Input: nums = [2,2,1]
Output: 1
Explanation: small
Input: nums = [4,1,2,1,2]
Output: 4
Explanation: middle
Input: nums = [7]
Output: 7
Explanation: single
Hint 1
XOR all the values together; pairs cancel out.