Skip to content

Commit a36eed7

Browse files
authoredMar 15, 2023
Create 167. Two Sum II - Input Array Is Sorted
1 parent 67164dc commit a36eed7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
 
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
vector<int> twoSum(vector<int>& numbers, int target) {
4+
int i=0;
5+
int j=numbers.size()-1;
6+
while(i<j)
7+
{
8+
if(numbers[i]+numbers[j]==target)
9+
return {i+1,j+1};
10+
11+
if(numbers[i]+numbers[j]>target)
12+
j--;
13+
else
14+
i++;
15+
}
16+
17+
return {i+1,j+1};
18+
}
19+
};

0 commit comments

Comments
 (0)
Please sign in to comment.