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