algorythms
Arrays & Hashing
LC #217Easy

Contains Duplicate

Arrays & Hashing
AmazonAppleGoogleMicrosoft

Problem

Given an integer array nums, return true if any value appears at least twice, or false if every element is distinct. Example: [1,2,3,1] → true (1 appears twice). [1,2,3,4] → false.

arrayhash-setsorting

Constraints

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

Example

Inputnums = [1, 2, 3, 1]
Outputtrue
Why

1 appears at index 0 and index 3

Hints — reveal one at a time