-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoSum.cpp
More file actions
37 lines (34 loc) · 751 Bytes
/
TwoSum.cpp
File metadata and controls
37 lines (34 loc) · 751 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>
using namespace std;
class Solution
{
public:
vector<int> twoSum(vector<int>& nums, int target)
{
int n=nums.size();
for (int i = 0; i < n; i++)
{
for (int j = i+1; j < n; j++)
{
if (nums[i] + nums[j] == target)
{
return {i,j};
}
}
}
return {};
}
};
int main()
{
// Solution test;
// vector<int> nums={2,7,11,15};
// int target = 9;
// vector<int> result=test.twoSum(nums,target);
// for (auto i : result)
// {
// cout<<i<<endl;
// }
// return 0;
}