Skip to content

Latest commit

 

History

History
44 lines (30 loc) · 1.06 KB

_167. Two Sum II - Input Array Is Sorted.md

File metadata and controls

44 lines (30 loc) · 1.06 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 14, 2024

Last updated : July 01, 2024


Related Topics : Array, Two Pointers, Binary Search

Acceptance Rate : 62.51 %


Solutions

Python

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]