Two Sum II
The solution to the Question-
Solution to the above Question
class Solution {
public:
vector<int> twoSum(vector<int>& nums,
int target) {
int start=0;
vector<int>v;
int end=nums.size()-1;
int sum=0;
while(end>start){
sum=nums[start]+nums[end];
if(sum>target){
end--;
}
if(sum<target){
start++;
}
if(sum==target){
v.push_back(start+1);
v.push_back(end+1);
return v;
}
}
return v;
}
};
0 Comments
If you have any doubts/suggestion/any query or want to improve this article, you can comment down below and let me know. Will reply to you soon.