# Code

• Submit Code
``````class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
slow = 0
fast = len(numbers) - 1

while(slow < fast):
sum = numbers[slow] + numbers[fast]

if(sum == target):
return [slow + 1,fast + 1]
elif(sum < target):
slow += 1
elif(sum > target):
fast -= 1
``````
• Full Code
``````class Solution:
def twoSum(self, numbers, target):
slow = 0
fast = len(numbers) - 1

result = []

while(slow < fast):
print("slow" + str(numbers[slow])  + "\tfast" + str(numbers[fast]))
sum = numbers[slow] + numbers[fast]
if(sum == target):
return ([slow+1,fast+1])
result.append(slow+1)
result.append(fast+1)
# return result
elif(sum < target):
slow += 1
elif(sum > target):
fast -= 1

S = Solution()
In = [2,7,11,15]
target = 9
print(S.twoSum(In,target))
``````

### 要不赞赏一下?

 微信 支付宝 PayPal Bitcoin

``https://www.emperinter.info/2022/02/22/two-sum-ii-input-array-is-sorted/``

 阿里云国际版 20美元 Vultr 10美元 搬瓦工 | Bandwagon 应该有折扣吧？ Just My Socks JMS9272283 【注意手动复制去跳转】 域名 | namesilo `emperinter`(1美元) 币安 币安