Problem: https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
| 1 | /** Problem: https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ */ |
| 2 | class Solution { |
| 3 | public int[] twoSum(int[] numbers, int target) { |
| 4 | int left = 0; |
| 5 | int right = numbers.length - 1; |
| 6 | |
| 7 | while (left < right) { |
| 8 | int sum = numbers[left] + numbers[right]; |
| 9 | if (sum == target) { |
| 10 | return new int[] {left + 1, right + 1}; |
| 11 | } else if (sum < target) { |
| 12 | left++; |
| 13 | } else { |
| 14 | right--; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | return null; |
| 19 | } |
| 20 | } |
nothing calls this directly
no outgoing calls
no test coverage detected