Single Number
Easy · hash map
A warehouse scans a batch of crates. Every crate carries an integer tag, and every tag was scanned exactly twice, except for one tag that was scanned only once.
Given the list nums of scanned tags (in no particular order), return the tag that appears exactly once.
Examples
Example 1
Input: nums = [2, 2, 1]
Output: 1
The tag 2 appears twice and the tag 1 appears once.
Example 2
Input: nums = [4, 1, 2, 1, 2]
Output: 4
1 and 2 each appear twice, so 4 is the odd one out.
Example 3
Input: nums = [-7]
Output: -7
Constraints
- 1 <= len(nums) <= 3 * 10^4
- len(nums) is odd.
- -10^9 <= nums[i] <= 10^9
- Exactly one value appears once; every other value appears exactly twice.