Skip to content

Commit 7f66386

Browse files
Create Two Sum
1 parent 24e026d commit 7f66386

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Two Sum

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

0 commit comments

Comments
 (0)