-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainsDuplicate.java
More file actions
50 lines (46 loc) · 1.28 KB
/
ContainsDuplicate.java
File metadata and controls
50 lines (46 loc) · 1.28 KB
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
46
47
48
49
50
<<<<<<< HEAD
//217. Contains Duplicate
class Solution {
public boolean containsDuplicate(int[] nums) {
Arrays.sort(nums);
for(int i=1;i<nums.length;i++){
if(nums[i] == nums[i-1]) return true;
}
return false;
}
}
// class Solution {
// public boolean containsDuplicate(int[] nums) {
// HashMap<Integer,Integer> map = new HashMap<>();
// for(int num : nums){
// map.put(num, map.getOrDefault(num, 0) + 1);
// }
// for(int freq : map.values()){
// if(freq > 1) return true;
// }
// return false;
// }
=======
//217. Contains Duplicate
class Solution {
public boolean containsDuplicate(int[] nums) {
Arrays.sort(nums);
for(int i=1;i<nums.length;i++){
if(nums[i] == nums[i-1]) return true;
}
return false;
}
}
// class Solution {
// public boolean containsDuplicate(int[] nums) {
// HashMap<Integer,Integer> map = new HashMap<>();
// for(int num : nums){
// map.put(num, map.getOrDefault(num, 0) + 1);
// }
// for(int freq : map.values()){
// if(freq > 1) return true;
// }
// return false;
// }
>>>>>>> be6ce0b427078b1421d5dd74adb2300dc02daeec
// }