HTMLify

LeetCode - Two Sum II - Input Array Is Sorted - Python
Views: 8 | Author: abh
class Solution:
    def twoSum(self, numbers: List[int], target: int) -> List[int]:
        last_i = None
        for i in range(0, len(numbers)-1):
            if numbers[i] == last_i:
                continue
            for j in range(i+1, len(numbers)):
                s = numbers[i] + numbers[j]
                if s == target:
                    return [i+1, j+1]
                if s > target:
                    break
            last_i = numbers[i]

Comments