Single Number
Easy · Bit Manipulation · Array · Bit Manipulation
Problem
Every element in nums appears twice except for one, which appears once. Return that one.
Solve it in linear time using constant extra space.
Examples
Input: nums = [2,2,1] Output: 1
Input: nums = [4,1,2,1,2] Output: 4
Constraints
- 1 <= len(nums) <= 3 * 10^4
- Every element appears twice except one
- -3 * 10^4 <= nums[i] <= 3 * 10^4
Approaches
- Set toggle — time O(n), space O(n)
Related problems
Start free on Cariara · Coding problems · System design studio