Single Number
Easy
LC #136
bit manipulationxorNot attempted yet
In nums, every value appears exactly twice except for
one value that appears once. Return that lonely value.
Aim for O(n) time and O(1) extra space.
Example 1
Input: nums = [2, 2, 1]
Output: 1
Example 2
Input: nums = [4, 1, 2, 1, 2]
Output: 4
Example 3
Input: nums = [1]
Output: 1
Constraints
- 1 ≤ len(nums) ≤ 2 · 10⁵ (odd length)
- -10⁹ ≤ nums[i] ≤ 10⁹
- exactly one value appears once