Contains Duplicate in Array

Easy
154
8
64.9% Acceptance

In this lab, you will be working on a function to check if an integer array contains a duplicate element. You have to implement a function containsDuplicate that returns true if any value appears at least twice in the array, and return false if every element is distinct.

Function signature

/** * @param {number[]} nums * @return {boolean} */ var containsDuplicate = function(nums) { };

Example

Here are some examples to help you understand the problem better:

Example 1:

Input: nums = [1,2,3,1] Output: true

Example 2:

Input: nums = [1,2,3,4] Output: false

Example 3:

Input: nums = [1,1,1,3,3,4,3,2,4,2] Output: true

Constraints:

  • 1 <= nums.length <= 105
  • -109 <= nums[i] <= 109

Challenges

  1. Export the function containsDuplicate.
  2. Implement the function containsDuplicate so that it returns true if the array contains duplicate elements and false otherwise.