-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path217.cpp
More file actions
38 lines (30 loc) · 712 Bytes
/
217.cpp
File metadata and controls
38 lines (30 loc) · 712 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
#include <unordered_set>
#include <vector>
#include <iostream>
using namespace std;
class Solution
{
public:
bool containsDuplicate(vector<int> &nums)
{
unordered_set<int> set;
for (const signed int num : nums)
{
if (set.count(num))
return true;
set.insert(num);
}
return false;
}
};
int main()
{
Solution sol;
vector<int> test1 = {1, 2, 3, 1};
vector<int> test2 = {1, 2, 3, 4};
vector<int> test3 = {1, 1, 1, 3, 3, 4, 3, 2, 4, 2};
cout << sol.containsDuplicate(test1) << endl;
cout << sol.containsDuplicate(test2) << endl;
cout << sol.containsDuplicate(test3) << endl;
return 0;
}