Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Problem

Contains Duplicate

LeetCode #217Easy
Any value appear twice?

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

Asked atAmazonAppleGoogle
step 1 / 16
3
1
4
1
5
[0][1][2][3][4]
Brute force
1for i ← 0 to n − 2:
2 for ji + 1 to n − 1:
3 if arr[i] == arr[j]:
4 return true
5return false
state

line 1Return true if any value appears at least twice.