-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.cpp
More file actions
43 lines (31 loc) · 790 Bytes
/
Solution.cpp
File metadata and controls
43 lines (31 loc) · 790 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
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
class Solution{
public:
vector<int> twoSum(vector<int> nums, int target){
vector<int> result;
int second_number;
for(int i=0; i<nums.size()-1; i++){
for(int j=i+1; j<nums.size(); j++){
if (target == nums[i]+nums[j]){
result.push_back(i);
result.push_back(j);
}
}
}
return result;
}
};
int main(int argc, char const *argv[]){
Solution s;
vector<int> nums;
nums.push_back(3);
nums.push_back(2);
nums.push_back(4);
int target = 6;
vector<int> result = s.twoSum(nums, target);
cout<<result[0]<<" "<<result[1];
return 0;
}