:type nums: List[int] :type target: int :rtype: List[int]
(self, nums, target)
| 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 |