Skip to content

Commit

Permalink
Time: 132 ms (5.45%), Space: 14.9 MB (100%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
mj3smile committed Dec 22, 2024
1 parent 5b84522 commit 7e44662
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
left, right = 0, len(numbers) - 1

while numbers[left] + numbers[right] != target:
total = numbers[left] + numbers[right]

if total > target and (numbers[right] > target or target - numbers[right] < numbers[left]):
left = 0
right = len(numbers) - 1

while left < right:
result = numbers[left] + numbers[right]

if result == target:
return [left + 1, right + 1]
elif result > target:
right -= 1
else:
elif result < target:
left += 1

return [left + 1, right + 1]

0 comments on commit 7e44662

Please sign in to comment.