iq.lab
Python starts when a code cell comes near or you run one
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
Inputnums = [4, 1, 7, 1]OutputTrue

The value 1 sits at positions 1 and 3.

Example 2
Inputnums = [5, 3, 8]OutputFalse

Three different values.

Example 3
Inputnums = []OutputFalse

No 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.

⌘+Enter runs 0:00Python starts when a code cell comes near or you run one
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.