> For the complete documentation index, see [llms.txt](https://ucan.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ucan.gitbook.io/notes/two-pointers/167.-two-sum-ii-input-array-is-sorted.md).

# 167. Two Sum II - Input array is sorted

```java
class Solution {
    public int[] twoSum(int[] numbers, int target) {
        // two pointers
        int start = 0, end = numbers.length-1;
        while(start<end){
            int sum = numbers[start]+numbers[end];
            if(sum==target){
                return new int[]{start+1, end+1};
            }else if(sum>target){
                end--;
            }else{
                start++;
            }
        }
        return null;
    }
}
```
