solution accepted, beats 51% runtime
This commit is contained in:
parent
11f76be23e
commit
3456cd63be
@ -4,7 +4,10 @@ def twoSum(numbers, target):
|
|||||||
:type target: int
|
:type target: int
|
||||||
:rtype: List[int]
|
:rtype: List[int]
|
||||||
"""
|
"""
|
||||||
last = len(numbers)-1
|
if target >= 0:
|
||||||
|
last = len(numbers)-1
|
||||||
|
else:
|
||||||
|
last = 1
|
||||||
# print( last)
|
# print( last)
|
||||||
while last > 0:
|
while last > 0:
|
||||||
if numbers[last] > target and target > 0:
|
if numbers[last] > target and target > 0:
|
||||||
@ -15,7 +18,10 @@ def twoSum(numbers, target):
|
|||||||
for x in range(len(numbers)):
|
for x in range(len(numbers)):
|
||||||
if numbers[x] + numbers[last] == target:
|
if numbers[x] + numbers[last] == target:
|
||||||
return [x+1, last+1]
|
return [x+1, last+1]
|
||||||
last -= 1
|
if target >= 0:
|
||||||
|
last -= 1
|
||||||
|
else:
|
||||||
|
last += 1
|
||||||
|
|
||||||
|
|
||||||
print(twoSum([2,7,11,15], 9))
|
print(twoSum([2,7,11,15], 9))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user