-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path217.txt
56 lines (38 loc) · 1.04 KB
/
217.txt
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
51
52
53
54
55
56
1.hash
//O(n), O(n)
#include <map>
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
unordered_map<int,int> dict;
for(int num :nums){
dict[num]+=1;
if(dict[num] > 1) return true;
}
return false;
}
};
2.排序
//O(nlogn)
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
sort(nums.begin(),nums.end());
for(int i = 0 ;i < nums.size()-2;i++){
if(nums[i]==nums[i+1] ) return true;
}
return false;
}
};
2.排序
//O(nlogn)
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
sort(nums.begin(),nums.end());
for(int i = 0 ;i < nums.size()-2;i++){
if(nums[i]==nums[i+1] ) return true;
}
return false;
}
};