Skip to content

Latest commit

 

History

History
16 lines (15 loc) · 496 Bytes

167. Two Sum II - Input array is sorted.md

File metadata and controls

16 lines (15 loc) · 496 Bytes

167. Two Sum II - Input array is sorted (Easy)

[tag] two pointers

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