twoSumSortedInput assumes that nums is sorted.
(nums []int, target int)
| 23 | |
| 24 | // twoSumSortedInput assumes that nums is sorted. |
| 25 | func twoSumSortedInput(nums []int, target int) []int { |
| 26 | numsLen := len(nums) |
| 27 | if numsLen < 2 { |
| 28 | return []int{} |
| 29 | } |
| 30 | |
| 31 | front := 0 |
| 32 | rear := numsLen - 1 |
| 33 | for front != rear { |
| 34 | twoSum := nums[front] + nums[rear] |
| 35 | if twoSum == target { |
| 36 | return []int{ |
| 37 | front, |
| 38 | rear, |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | if twoSum < target { |
| 43 | front++ |
| 44 | } else { |
| 45 | rear-- |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return []int{} |
| 50 | } |
nothing calls this directly
no outgoing calls
no test coverage detected