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.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay