Asked at

Contains Duplicate

Easy
Verified
SetArrayHash Map~10 min

Given an integer array nums, return true if any value appears at least twice.

Track values seen so far in a set; a repeat means a duplicate.

The input arrives as a single array nums.

Examples

in[1, 2, 3, 1]
outtrue

1 appears twice.

in[1, 2, 3, 4]
outfalse

All values are distinct.

Constraints

  • 1 ≤ nums.length ≤ 10⁵
  • -10⁹ ≤ nums[i] ≤ 10⁹

Get help

🔑

Sign in to solve

Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.