python leetcode 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]
        """ 
        ln=len(numbers)
        i=0
        j=ln-1
        while i<j:
            onesum=numbers[i]+numbers[j]
            if onesum==target:
                return [i+1,j+1]
            elif onesum>target:
                j-=1
            else:
                i+=1

猜你喜欢

转载自blog.csdn.net/Neekity/article/details/85013114