AlgoFrames

Contains duplicate

Warm-up · Write code · about 8 min

Given an integer array nums, return true if any value appears at least twice. Return false if every value is distinct.

Example 1

Input:

[[1,2,3,1]]

Output:

true

1 appears at index 0 and index 3.

Example 2

Input:

[[1,2,3,4]]

Output:

false

Constraints

  • 0 ≤ nums.length ≤ 10,000
  • -1,000,000 ≤ nums[i] ≤ 1,000,000

Learn the idea first: Hash sets and maps in practice: counting, lookup, deduplication, a visual lesson.

More Hash sets and maps in practice: counting, lookup, deduplication problems