Menu
CoddyTech

Contains Duplicate

EasyHashingpython iconjava iconcpp iconc iconjs icon+10

You get an array of integers nums. Return true if some value appears in it at least twice, and false if every value is different.

Function

containsDuplicate(nums: integer-array) → boolean
numsinteger-array
the integers to check
Returnsboolean
true if some value appears at least twice, false otherwise

Constraints

  • 1 ≤ nums.length ≤ 104
  • -109 ≤ nums[i] ≤ 109

Examples

Input
nums = [3, 1, 4, 1, 5]
Output
true
Explanation
The value 1 appears at index 1 and again at index 3, so the answer is true.

lock icon+17 hidden tests on Submit

challenge icon

Follow-up

Can you stop as soon as you meet the first repeated value, instead of always reading the whole array?

Reset code
def containsDuplicate(nums):
    # Write code here
Test cases

Case 1

Case 2

Case 3

Input

nums = [3, 1, 4, 1, 5]

Expected

true