167.Two Sum II - Input array is sorted

 

 

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

 

posted @ 2020-05-09 14:55  星海寻梦233  阅读(70)  评论(0编辑  收藏  举报