-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1TwoSum.cpp
More file actions
34 lines (30 loc) · 754 Bytes
/
Copy path1TwoSum.cpp
File metadata and controls
34 lines (30 loc) · 754 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
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
vector<int> twoSum (vector<int>& nums, int target){
int count = nums.size();
for (int i = 0;i < count; i++){
for (int j = i+1; j < count;j++){
if (nums[i] + nums[j] == target) {
vector<int> res;
res.push_back(i);
res.push_back(j);
return res;
}
}
}
}
};
int main()
{
Solution m;
int n[] = {2, 7, 11, 15};
vector<int> nums(n, n+4);
int target = 9;
vector<int> res = m.twoSum(nums, target);
for (int i = 0; i < res.size(); i++)
cout << res[i] << endl;
return 0;
}