-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution217.java
More file actions
45 lines (42 loc) · 986 Bytes
/
Copy pathSolution217.java
File metadata and controls
45 lines (42 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* @Title: Solution217.java——
* @Package EasyCode_01
* @Description: TODO
* @author msdumin@gmail.com
* @date 2019年3月26日 下午11:04:57
* @version V1.0
*/
package EasyCode_01;
import java.util.HashMap;
import java.util.Map;
/**
* @ClassName: Solution217——
* @Description: TODO
* @author msdumin@gmail.com
* @date 2019年3月26日 下午11:04:57
*/
public class Solution217 {
public boolean containsDuplicate(int[] nums) {
//非暴力解法:
Map<Integer, Integer> map = new HashMap<>();
for(int i = 0 ; i < nums.length ; i++){
if(map.containsKey(nums[i]))
map.put(nums[i], map.get(nums[i]) + 1);
else
map.put(nums[i], 1);
}
for(Integer key : map.keySet()){
if(map.get(key) > 1)
return true;
}
return false;
// //暴力解法:超时了
// for (int i = 0; i < nums.length; i++) {
// for(int j = i + 1 ; j < nums.length ; j ++){
// if(nums[j] == nums[i])
// return true;
// }
// }
// return false;
}
}