python solution with one pointer

  • 0

    use one pointer p starts from list end and travels backwards. 32 ms run time
    class Solution(object):
    def twoSum(self, numbers, target):
    for i, n in enumerate(numbers):
    while p>i and numbers[p]>target-n:
    if numbers[p2]==target-n:
    return [i+1,p+1]

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.