解题思路:一般给定的数组或链表是有序的话就要相当双指针了,因为此时左指针向右,右指针向左的移动都代表着数字的增大或减小,这样的移动s 包含信息的。
class Solution {
public int[] twoSum(int[] numbers, int target) {
int left = 0, right = numbers.length - 1;
while(left < right){
int sum = numbers[left] + numbers[right];
if(sum < target){
left++;
}else if(sum > target){
right--;
}else{
return new int[]{left + 1,right + 1};
}
}
return new int[]{-1,-1};
}
}



