Code Lab

Contains duplicate

EasyMap and Set3 min

Write a function containsDuplicate(nums). It takes an array of numbers and returns true if some number occurs in it at least twice. If all numbers are different, return false.

Examples

containsDuplicate([1, 2, 3, 1])

Returns true

The number 1 occurs twice.
containsDuplicate([1, 2, 3, 4])

Returns false

Source

Loading the editor...
  1. InputcontainsDuplicate([ 1, 2, 3, 1 ])
    Expectedtrue
  2. InputcontainsDuplicate([ 1, 2, 3, 4 ])
    Expectedfalse
  3. InputcontainsDuplicate([ 1, 1, 1, 3, 3, 4, 3, 2, 4, 2 ])
    Expectedtrue

Hidden tests run on Submit.