Solution to Contains Duplicate by LeetCode

20 Aug


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 *