Contains Duplicate
Easy · Arrays & Hashing · Array · Hash Table · Sorting
Problem
Given an integer array nums, return True if any value appears at least twice, and False if every element is distinct.
Examples
Input: nums = [1,2,3,1] Output: True
1 appears twice.
Input: nums = [1,2,3,4] Output: False
Constraints
- 1 <= len(nums) <= 10^5
- -10^9 <= nums[i] <= 10^9
Approaches
- Length comparison — the one-liner — time O(n), space O(n)
Related problems
Start free on Cariara · Coding problems · System design studio