A shorter version,

public int[] twoSum(int[] numbers, int target) { // Have two pointer at the beginning and at the end of the array int i=0, j=numbers.length-1; while (i<j) { if (numbers[i] + numbers[j] < target) i++; else if (numbers[i] + numbers[j] > target) j--; else return new int[] {i+1, j+1}; } return new int [2]; }Two Sum II - Input array is sorted