DEV Community

Lautaro Suarez
Lautaro Suarez

Posted on

1

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)

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay