Skip to content

Commit b155433

Browse files
committed
FEAT : upload #219
1 parent 13719f3 commit b155433

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

two-sum/crumbs22.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
class Solution {
8+
public:
9+
vector<int> twoSum(vector<int>& nums, int target) {
10+
if (nums.size() == 2)
11+
return {1, 2};
12+
int tmp;
13+
for (int i = 0; i < nums.size(); i++)
14+
{
15+
tmp = target - nums[i];
16+
for (int j = i + 1; j < nums.size(); j++)
17+
{
18+
if (nums[j] == tmp)
19+
{
20+
return {i, j};
21+
}
22+
}
23+
}
24+
return {-1};
25+
}
26+
};

0 commit comments

Comments
 (0)