Dashboard
LC #136
Single Number
Pattern · ?AmazonGoogleMicrosoftApple
Problem
Every element appears twice except one. Find that single element using O(1) space.
Constraints
- 1 ≤ n ≤ 3 × 10⁴
- -3 × 10⁴ ≤ nums[i] ≤ 3 × 10⁴
- Exactly one element appears once; all others appear twice
- O(1) extra space required
Example
- Input
- nums = [4, 1, 2, 1, 2]
- Output
- 4
- Why
- 1^1=0, 2^2=0, 0^4=4. Every pair cancels; only 4 remains
Spot the pattern
Which pattern cracks it?
Hints
One at a time