DEV Community

Lautaro Suarez
Lautaro Suarez

Posted on

Contains Duplicate

Second day posting about Blind 75 LeetCode Questions.

Today i will be solving the Contains Duplicate problem.

Let`s set up the problem first.

We are being asked to return true if the value of an array appears at least twice and return false if every element is distinct.

We will start by defining a variable creating a new Map()

Image description

Next we are going to create a for loop to iterate over the array given.
The next line we are going to check in the if statement if the array has "nums[i]" which is the array given when looping over it and it will return true if it is true the statement given.
And then an else statement that will set to the "arr", "nums[i]" and "true" as follows.
And Finally return a "false" in case of otherwise.

Image description

Thanks, i will be uploading every day.
Hope someone found it useful.

Lautaro.

Top comments (0)