/** 
 *	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.
 *
 *	Author: matao
 *
 */

import java.util.Map;
import java.util.HashMap;

public class ContainsDuplicate {
	public static boolean containsDuplicate(int[] nums) {
		if(nums == null || nums.length == 0) {
			return false;
		}

		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		for (int i = 0; i < nums.length; i++) {
			if(map.containsKey(nums[i])) {
				return true;
			}	
			map.put(nums[i], nums[i]);
		}
		return false;
    }

    public static void main(String[] args) {
    	int[] nums1 = {1, 2, 3, 3};
    	int[] nums2 = {1, 3, 5, 6};
    	System.out.println(containsDuplicate(nums1));
    	System.out.println(containsDuplicate(nums2));
    }
}
@@ -330,16 +330,28 @@
 icate %7B%0A
+%09// HashMap%0A
 %09public 
@@ -382,16 +382,17 @@
 uplicate
+1
 (int%5B%5D n
@@ -680,16 +680,832 @@
 %0A    %7D%0A%0A
+    // %E6%8E%92%E5%BA%8F%E5%90%8E%E5%86%8D%E5%88%A4%E6%96%AD, %E9%A1%BA%E4%BE%BF%E7%BB%83%E4%B9%A0%E5%BF%AB%E6%8E%92%0A    public static boolean containsDuplicate2(int%5B%5D nums) %7B%0A    %09qSort(nums);%0A    %09for (int i = 0; i %3C nums.length - 1; i++) %7B%0A    %09%09if(nums%5Bi%5D == nums%5Bi+1%5D) %7B%0A    %09%09%09return true;%0A    %09%09%7D%0A    %09%7D%0A    %09return false;%0A    %7D%0A%0A    public static void qSort(int%5B%5D nums) %7B%0A    %09quickSort(nums, 0, nums.length - 1);%0A    %7D %0A%0A    public static void quickSort(int%5B%5D nums, int left, int right) %7B%0A    %09if(left %3C right) %7B%0A    %09%09int i = left, j = right;%0A    %09%09int pivot = nums%5Bleft%5D;%0A    %09%09while(i %3C j && nums%5Bj%5D %3E= pivot) j--;%0A    %09%09while(i %3C j && nums%5Bi%5D %3C= pivot) i++;%0A    %09%09if(i %3C j) %7B%0A    %09%09%09int temp = nums%5Bi%5D;%0A    %09%09%09nums%5Bi%5D = nums%5Bj%5D;%0A    %09%09%09nums%5Bj%5D = temp;%0A    %09%09%7D%0A    %09%09nums%5Bleft%5D = nums%5Bi%5D;%0A    %09%09nums%5Bi%5D = pivot;%0A    %09%09quickSort(nums, left, i - 1);%0A    %09%09quickSort(nums, j + 1, right);%0A    %09%7D%0A    %7D%0A%0A
     publ
@@ -1601,12 +1601,15 @@
 %7B1, 
-3, 5
+5, 2, 3
 , 6%7D
@@ -1647,24 +1647,25 @@
 insDuplicate
+1
 (nums1));%0A  
@@ -1703,16 +1703,121 @@
 uplicate
+1(nums2));%0A    %09System.out.println(containsDuplicate2(nums1));%0A    %09System.out.println(containsDuplicate2
 (nums2))

add new solution