Solution to Contains Duplicate by LeetCode

20 Aug

Question: https://leetcode.com/problems/contains-duplicate/

Question Name: Contains Duplicate

In general, I found two solutions. The first solution is using hash set:

The second solution is using sorting. We could sort the input and check each pair of adjacent items. Or we could early terminate the sorting if we found two same numbers.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!