# 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.
（一个整型数组，如果数组中的数据至少出现两次，则返回true，如果数组中的数据只出现一次，则返回false）

public class Solution {
public static boolean containsDuplicate(int[] nums) {
int length = nums.length;
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for(int i = 0 ; i < length; i++){
if(map == null){
map.put(nums[i], 1);
}else{
if(!map.containsKey(nums[i])){
map.put(nums[i], 1);
}else{
map.put(nums[i], 2);
}
}
}
if(map.containsValue(2)){
return true;
}

return false;
}

public static void main(String[] args) {
int[] nums = {3,1,3,4,5,6,7,78};
boolean flag = containsDuplicate(nums);
System.out.println(flag);
}
}

public static  boolean containsDuplicate(int[] nums) {
int length = nums.length;
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for(int i = 0 ; i < length; i++){
if(map == null){
map.put(nums[i], 1);
}else{
if(!map.containsKey(nums[i])){
map.put(nums[i], 1);
}else{
map.put(nums[i], 2);
return true;
}
}
}

return false;
}

#### Eclipse或MyEclipse 报错 “build path contains duplicate entry..."解决方法

2013-12-05 11:35:27

#### 217. Contains Duplicate [easy] (Python)

2016-05-14 19:39:50

#### Build path contains duplicate entry:'src' for project 'XXX'

2014-05-20 10:04:35

#### 【LeetCode-面试算法经典-Java实现】【219-Contains Duplicate II（包含重复元素II）】

2015-08-29 06:36:21

#### Build path contains duplicate entry: '...e/lib/rt.jar' for project 'MyQQClient'解决

2012-06-06 20:58:46

#### Build path contains duplicate entry——生成路径包含重复项

2017-04-01 10:22:21

#### Eclipse: Importing project - build path contains duplicate entry: 'src' for project

2015-07-25 18:26:54

#### android build path contains duplicate entry:'src' for project XXX

2014-12-16 14:42:40

#### leetcode 220: Contains Duplicate III

2015-06-02 08:31:05

#### leetcode笔记：Contains Duplicate III

2016-02-26 15:43:16