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

# 167. Two Sum II - Input array is sorted

<https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/>

## solution

* 注意两个index不一定连续

```python
class Solution:
    def twoSum(self, numbers: List[int], target: int) -> List[int]:
        l = 0
        r = len(numbers) - 1
        while l < r:
            s = numbers[l] + numbers[r]
            if s == target:
                return [l+1, r+1]
            elif s < target:
                l += 1
            else:
                r -= 1
```

时间复杂度：O()\
空间复杂度：O()
