Skip to content
BASA DSA

Single Number

EasyBit Manipulation

Every integer in nums occurs twice except one that occurs once. Return the unpaired value using linear time and constant auxiliary space.

Example 1

Input
nums = [4,2,4,9,2]
Output
9

Explanation

The pairs of 4 and 2 cancel under XOR, leaving 9.

Example 2

Input
nums = [-1]
Output
-1

Explanation

A singleton is its own unpaired value, including a negative value.

Example 3

Input
nums = [0,3,3]
Output
0

Explanation

The 3 pair cancels, leaving unique value zero.

Constraints

  • 1 <= len(nums) <= 30000
  • Values are signed 32-bit integers

Function contractsingleNumberArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…