Skip to main content
Back to problems
Leetcode
Medium
Arrays
Bit Manipulation
Google
Meta
Single Number III

Find the two values that appear exactly once when every other value appears twice.

Acceptance 0%
Problem Statement

You are given an integer array in which exactly two numbers appear once and every other number appears exactly twice.

Return the two unique numbers in any order.

A good solution should use constant extra space and run in linear time.

Input Format

  • An integer array nums.
  • Exactly two elements appear once.
  • Every other element appears exactly twice.

Output Format

Return an array containing the two numbers that appear once, in any order.

Constraints

  • 2nums.length2 \le nums.length
  • The array contains exactly two numbers that occur once.
  • All other numbers occur exactly twice.
  • Try to use O(n)O(n) time and O(1)O(1) extra space.
Examples
Sample cases returned by the problem API.

Example 1

Input

[1,2,1,3,2,5]

Output

[3,5]

Explanation

The numbers 3 and 5 appear once. The others appear twice.

Example 2

Input

[-1,0,-1,4]

Output

[0,4]

Explanation

The values 0 and 4 occur only once.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.