Single Number III
In an array where every element appears exactly twice except for two elements that each appear once, find those two single elements. The answer may be returned in any order, and the solution must run in linear time using constant extra space.
Open official problem prompt ↗Recover the only two non-repeating values from a stream where everything else is duplicated, using no auxiliary storage.
Imagine matching socks tumbling out of a dryer. Pair them up and they vanish from consideration; you are left holding two odd socks. To tell them apart you find one feature where they differ (say, one has a stripe) and sort by that feature so each odd sock lands in its own pile.
- Input
- nums = [1, 2, 1, 3, 2, 5]
- Output
- [3, 5]
- Why
- 1 and 2 each appear twice and cancel; 3 and 5 are the two that appear only once.
2 <= nums.length <= 3 * 10^4-2^31 <= nums[i] <= 2^31 - 1Each integer appears exactly twice except two that appear onceThe result can be returned in any order