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

Method _twoSum

Array/two_sum.py:58–76  ·  view source on GitHub ↗

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

(self, nums, target)

Source from the content-addressed store, hash-verified

56
57
58 def _twoSum(self, nums, target):
59 """
60 :type nums: List[int]
61 :type target: int
62 :rtype: List[int]
63 """
64
65 sortedNums = sorted(nums)
66 start = 0
67 end = len(sortedNums) - 1
68 while start <= end:
69 # print(nums[start] + nums[end])
70 if sortedNums[start] + sortedNums[end] == target:
71 return sortedNums[start], sortedNums[end]
72
73 if sortedNums[start] + sortedNums[end] > target:
74 end -= 1
75 else:
76 start += 1
77
78 # def binarySearch(self, rawList, target):
79 # split = len(rawList) // 2

Callers 1

twoSumMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected