Contains Duplicate

Easy#217find a pair

You get an array of numbers. Find out whether some number appears in it at least twice. Our example: [4, 9, 1, 7, 9, 2] — yes, 9 appears twice.

input
nums: an array of integers.
returns
true if some number appears in nums at least twice, false if all the numbers are different.
constraints
  • 1 ≤ nums.length ≤ 1000
  • −10⁹ ≤ nums[i] ≤ 10⁹
our 9 tests keep to them
examples
Open a test in the tests panel: it shows the input and the expected answer.
/**
 * @param {number[]} nums
 * @return {boolean}
 */
function containsDuplicate(nums) {

}
Ctrl ↵
format
reset

saved in this browser

9 tests · limit 3 s

Stuck?

See the solution run step by step on our example, then why it works and its complexity.

Watch the walkthrough →

Next: more hash map problems

Pattern “Hash map” →

The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.