Problems

Single Number

easy
easy
arrays
bit-manipulation

Every value in nums appears exactly twice except one value that appears once. Return the unpaired value.

Input / output

  • Input: nums: integer[]
  • Output: the unique integer

Examples

  1. [2,2,1] returns 1.
  2. [4,1,2,1,2] returns 4.

Constraints

  • 1 <= nums.length <= 100,000
  • nums.length is odd
  • The input satisfies the pairing rule

Follow-up Why does XOR remove paired values regardless of their order?

Examples

Example 1

Input: nums = [2,2,1]
Output: 1

Example 2

Input: nums = [4,1,2,1,2]
Output: 4

Example 3

Input: nums = [1]
Output: 1
🔒 5 hidden

Running will execute all 8 cases, including 5 hidden ones.