Single Number

Very easy Bit Manipulation AI round

nums is a list of whole numbers.

Every value in nums appears exactly twice, except one value, which appears only once.

Return the value that appears once.

Example 1

Input: nums = [7,-2,5,7,5]
Output: -2

7 and 5 each appear twice, at positions 0 and 3 and at positions 2 and 4. -2 appears only once.

Example 2

Input: nums = [-4,9,9,-4,12,3,3]
Output: 12

Example 3

Input: nums = [0,13,-8,13,-8]
Output: 0

Constraints

  • 1 ≤ nums.length < 3 × 10⁵
  • -10⁹ ≤ nums[i] ≤ 10⁹
  • One value appears exactly once in nums, and every other value appears exactly twice

Watch the explanation

More Bit Manipulation

All Bit Manipulation problems