一.双指针
class Solution {
public:
vector<int> twoSum(vector<int>& numbers, int target) {
//双指针,左指针指向最左端,右指针指向最右端,然后不断逼近判断是否为target
int left=0;
int right=numbers.size()-1;
int sum=0;
vector<int> res;
while(left<right){
sum=numbers[left]+numbers[right];
if(sum==target){
res.push_back(left+1);
res.push_back(right+1);
return res;
}
if(sum<target){
left++;
}
if(sum>target){
right--;
}
}
return res;
}
};