-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwo_sum.cpp
More file actions
executable file
·41 lines (38 loc) · 903 Bytes
/
Copy pathtwo_sum.cpp
File metadata and controls
executable file
·41 lines (38 loc) · 903 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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> result;
int nums_size = nums.size();
for(auto i = 0; i < (nums_size - 1); i++)
{
for(auto j = i+1; j < nums_size; j++)
{
if((nums[i] + nums[j]) == target)
{
result.push_back(i);
result.push_back(j);
break;
}
}
}
return result;
};
};
int main(void)
{
Solution solution;
std::vector<int> nums = {-3,4,3,90};
std::vector<int> result;
int target = 0;
result = solution.twoSum(nums,target);
for(auto& itr : result)
{
std::cout << itr << " ";
}
std::cout << std::endl;
return 0;
}