-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.cpp
More file actions
37 lines (36 loc) · 798 Bytes
/
1.cpp
File metadata and controls
37 lines (36 loc) · 798 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
#include <iostream>
#include <vector>
class Solution
{
public:
std::vector<int> twoSum(std::vector<int>& nums, int target)
{
bool bFound = false;
int tobeZero = target;
std::vector<int> vOutput;
int i,j;
for(i=0; i<nums.size(); ++i)
{
tobeZero -= nums[i];
for(j=i+1; j<nums.size(); ++j)
{
if(tobeZero == nums[j])
{
bFound = true;
break;
}
}
if(bFound == true)
{
break;
}
else
{
tobeZero = target;
}
}
vOutput.push_back(i);
vOutput.push_back(j);
return vOutput;
}
};