167. Two Sum II - Input Array Is Sorted Poison 2023-05-10 Two Pointers 1234567891011121314151617class Solution { public int[] twoSum(int[] numbers, int target) { int i = 0, j = numbers.length - 1; while (i < j) { int sum = numbers[i] + numbers[j]; if (sum < target) { i++; } else if (sum > target) { j--; } else { return new int[]{i + 1, j + 1}; } } return new int[0]; }} 注意题目要求下标从 1 开始。 References167. Two Sum II - Input Array Is Sorted剑指 Offer II 006. 排序数组中两个数字之和