思路分析
代码如下
public int[] twoSum(int[] nums, int target) {
int left = 0, right = nums.length - 1;
while (left < right) {
int s = nums[left] + nums[right];
if (s == target) return new int[]{nums[left], nums[right]};
else if (s > target) right--;
else left++;
}
return new int[0];
}
原文:https://www.cnblogs.com/duduwy/p/13390534.html