The Blind 75 Leetcode Series: Contains Duplicate

Jonathan Chao
3 min readNov 17, 2022
Photo by Chris Ried on Unsplash

Today, we are working on 217. Contains Duplicate

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

This is a rather simple one. We are given a list of integers, and we just need to check if we see any duplicate in it.

Some questions to figure out before attempting this problem:

  1. how long is the list? Is there going to be a problem if I want to store it in memory?

…… that’s probably it honestly. This is a short and concise problem without too much vagueness.

If the interviewer tells us that we don’t have to worry about storing the entire list causing out-of-memory problem, then we can continue.

First approach is the brute-force, check-everything approach. We just want to find any duplicate, so we know that at some point in the list, two integers will be the same. Thus we create a double for-loop and check every element.

def containsDuplicate(nums]):
for i in range(len(nums) - 1):
for j in range(i+1, len(nums))…

--

--

Jonathan Chao

I am a software developer who has been in this industry for close to a decade. I share my experience to people who are or want to get into the industry