easyHash maps and sets target 15 min
Contains duplicate
Before you use a column as a key, you check that no value repeats. Write that check for a list of integers nums: return True when at least one value sits at two or more positions, and False when every value shows up only once.
An empty list has nothing to repeat, so it gives False.
Example 1
Input
nums = [4, 1, 7, 1]OutputTrueThe value 1 sits at positions 1 and 3.
Example 2
Input
nums = [5, 3, 8]OutputFalseThree different values.
Example 3
Input
nums = []OutputFalseNo values, so nothing repeats.
Constraints
0 ≤ len(nums) ≤ 105
-109 ≤ nums[i] ≤ 109
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.
Run examples checks the examples. Submit runs every test, including edge cases and, when the problem has one, a speed check on a large input.