BiruLyu
6/12/2017 - 6:09 PM

217. Contains Duplicate.java

start = 1, end = N - 1
mid = N / 2
count <= mid  ==> [mid+1, N - 1]
count > mid   ==> [start, mid - 1]
public class Solution {
    public boolean containsDuplicate(int[] nums) {
        HashSet<Integer> set = new HashSet<Integer>();
        for(int num : nums) {
            if(!set.add(num)) {
                return true;
            }
        }
        return false;
    }
}