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.

Billboard image

Monitor more than uptime.

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay