Friday, April 8, 2016

LeetCode Q217: Contains Duplicate

Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.

Solution
The normal solution is to use hash table:

However, the most efficient way as discussed in leetcode forum is to use stl set, as set will only contain unique elements

No comments:

Post a Comment