美文网首页
167. Two Sum II - Input array is

167. Two Sum II - Input array is

作者: 一个想当大佬的菜鸡 | 来源:发表于2019-06-13 13:59 被阅读0次
167. Two Sum II - Input array is sorted
class Solution(object):
    def twoSum(self, numbers, target):
        """
        :type numbers: List[int]
        :type target: int
        :rtype: List[int]
        """
        l, r = 0, len(numbers)-1
        while l < r:
            if numbers[l] + numbers[r] == target:
                return [l+1, r+1]
            elif numbers[l] + numbers[r] > target:
                r -= 1
            else:
                l += 1
        

相关文章

网友评论

      本文标题:167. Two Sum II - Input array is

      本文链接:https://www.haomeiwen.com/subject/joajfctx.html