All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 14, 2024
Last updated : July 01, 2024
Related Topics : Array, Two Pointers, Binary Search
Acceptance Rate : 62.51 %
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
left, right = 0, len(numbers) - 1
while left < right :
difference = target - numbers[right]
if numbers[left] == difference :
break
if difference < numbers[left] :
right -= 1
else :
left += 1
return [left + 1, right + 1]