solution accepted, beats 51% runtime

This commit is contained in:
Jacob Delgado 2023-09-01 21:36:51 -07:00
parent 11f76be23e
commit 3456cd63be

View File

@ -4,7 +4,10 @@ def twoSum(numbers, target):
:type target: int
:rtype: List[int]
"""
last = len(numbers)-1
if target >= 0:
last = len(numbers)-1
else:
last = 1
# print( last)
while last > 0:
if numbers[last] > target and target > 0:
@ -15,7 +18,10 @@ def twoSum(numbers, target):
for x in range(len(numbers)):
if numbers[x] + numbers[last] == target:
return [x+1, last+1]
last -= 1
if target >= 0:
last -= 1
else:
last += 1
print(twoSum([2,7,11,15], 9))