 All Problems
Single Number
easy
bit manipulation
arrays
amazon
microsoft
google

Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.

You must implement a solution with linear runtime complexity and use only constant extra space.

Example 1:

Input: 2 2 1
Output: 1

Example 2:

Input: 4 1 2 1 2
Output: 4

Example 3:

Input: 1
Output: 1

Constraints:

  • 1 ≤ nums.length ≤ 3 × 10⁴
  • -3 × 10⁴ ≤ nums[i] ≤ 3 × 10⁴
  • Each element appears exactly twice except for one element.

Input format: A single line of space-separated integers.

Output format: A single integer.

Run to check your code against the sample cases, or submit to run every case