leetcode/0167_two-sum-ii-input-array-is-sorted/python3/solution.py
2022-04-23 18:27:33 +05:30

16 lines
427 B
Python

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