Math Fundamentals18 sections · 814 units
Open in Course

Contains Duplicate - Algorithm

Hash set approach

1.1. Create an empty hash set.

2.2. For each element in the array:

3.3. If the element is already in the set, return truetrue.

4.4. Otherwise, add it to the set.

5.5. If the loop completes, return falsefalse.