Skip to main content
CodeOath
← All problems

Problem

Single Number

Easy
  • arrays
  • bit-manipulation

All the values in nums come in pairs, except one value that has no partner. Return the value with no partner. Your solution has to take O(n) time and O(1) extra space.

Example 1
Input
nums = [6, 3, 9, 3, 6]
Output
9
Explanation

the two 6s and the two 3s pair up, even though they are not next to each other. The 9 has no partner.

Example 2
Input
nums = [8]
Output
8
Explanation

the only element has nothing to pair with.

Constraints:

  • 1 <= nums.length <= 10^5, and nums.length is odd
  • -10^9 <= nums[i] <= 10^9
  • one value appears once, and every other value appears exactly twice

Tab indents. Press Esc, then Tab to leave the editor.

Run your code to see every test here. Nothing is submitted or recorded.