Arrays & Hashing
LC #217Easy
Contains Duplicate
Arrays & Hashing
AmazonAppleGoogleMicrosoftProblem
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
Input
nums = [1, 2, 3, 1]Output
trueWhy
1 appears at index 0 and index 3