Problems › Hashing

Contains Duplicate

Difficulty: Easy · Topic: Hashing

Given an integer array nums, return True if any value appears at least twice, and False if every element is distinct.

Examples

contains_duplicate([1,2,3,1])
→ true

1 appears twice.

contains_duplicate([1,2,3,4])
→ false
contains_duplicate([1,1,1,3,3,4,3,2,4,2])
→ true

Target complexity: time O(n), space O(n)

Write your solution in Python and run it against hidden tests right on this page. Progressive hints and Python + C++ reference solutions are included.

Learn the idea first: the lesson for this problem.

More Hashing problems