leetcode/0167_two-sum-ii-input-array.../python3/solution.py

16 lines
427 B
Python
Raw Normal View History

2022-04-23 12:57:33 +00:00
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