Skip to main content
Back to problems
Leetcode
Easy
Arrays
Hash Maps
Sets
Contains Duplicate

Determine whether any value appears at least twice in an array.

Acceptance 73%
Problem Statement

Given an integer array, decide whether the array contains any duplicate value. Return true if at least one number appears more than once; otherwise return false.

A good solution should be able to process the list efficiently by tracking what has already been seen.

Input Format

  • An integer array nums.
  • Each element may appear zero or more times.

Output Format

  • Return true if any value occurs at least twice.
  • Return false if all values are distinct.

Constraints

  • The array may be empty.
  • Values can be negative, zero, or positive.
  • Aim for better than O(n2)O(n^2) time if possible.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [1,2,3,1]

Output

true

Explanation

The value 1 appears twice.

Example 2

Input

nums = [1,2,3,4]

Output

false

Explanation

All values are distinct.

Show 1 more example

Example 3

Input

nums = [1,1,1,3,3,4,3,2,4,2]

Output

true

Explanation

Several values repeat, so the answer is true.

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.