Search⌘ K
AI Features

Single Number

Single Number gives you an integer array where every value appears twice except one. Return the unique value, using linear time and constant extra space.

Statement

Given an array of integers, where every element appears twice except for one, find the element that occurs only once.

Note: The solution must have linear runtime and constant space complexity.

Constraints:

  • 1≤1 \leq nums.length ≤103\leq 10^3
  • −3×103≤-3 \times 10^3 \leq nums[i] ≤3×103\leq 3 \times 10^3

Example

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Single Number

1.

From the given array of integers, find the number that appears once.

array = [1, 2, 4, 1, 2, 4, 9, 6, 7, 6, 7]

A.

1

B.

2

C.

9

D.

6


1 / 2

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5

Try it yourself

Implement your solution in the following coding playground:

Python
usercode > main.py
def single_number(nums):
# Replace this placeholder return statement with your code
return -1
Single Number