The Number Without a Pair

EasyHash Map≈ 10 min

You are given a list of integers nums. Every number in it appears exactly twice, except one number, which appears exactly once. Return that number.

The two copies of a pair can be anywhere in the list, not necessarily next to each other.

Examples

text
nums = [4, 1, 2, 1, 2]   →  4
nums = [7]               →  7
nums = [3, 9, 3]         →  9

In the first example 1 and 2 each appear twice, and 4 only once.

Constraints

  • Between 1 and 19,999 numbers, each between -1,000,000,000 and 1,000,000,000.
  • Exactly one number appears once; every other appears twice.
  • Aim for O(n): look at each number a constant number of times.
Sound off. Turn on for key clicks and a chime when the tests pass.Inline suggestions off. Recommended while you are learning. Turn on to complete words as you type.
Console
›Run to see what your code prints

Run checks the 3 visible cases here, in your browser. Submit runs all 7 on the judge, 4 of them hidden, and measures how your solution scales.