Leetcode 167 Solution

This article provides solution to leetcode question 167 (two-sum-ii-input-array-is-sorted)

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

Solution

class Solution:
    def twoSum(self, numbers: List[int], target: int) -> List[int]:
        l = 0
        r = len(numbers) - 1

        while l < r:
            if numbers[l] + numbers[r] == target:
                return [l + 1, r + 1]
            elif numbers[l] + numbers[r] > target:
                r -= 1
            else:
                l += 1