MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / twoSum

Method twoSum

Array/TwoSumIIAlreadySorted.py:24–41  ·  view source on GitHub ↗

:type numbers: List[int] :type target: int :rtype: List[int]

(self, sortedNums, target)

Source from the content-addressed store, hash-verified

22"""
23class Solution(object):
24 def twoSum(self, sortedNums, target):
25 """
26 :type numbers: List[int]
27 :type target: int
28 :rtype: List[int]
29 """
30
31 start = 0
32 end = len(sortedNums) - 1
33 while start <= end:
34 # print(nums[start] + nums[end])
35 if sortedNums[start] + sortedNums[end] == target:
36 return start+1, end+1
37
38 if sortedNums[start] + sortedNums[end] > target:
39 end -= 1
40 else:
41 start += 1
42

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected