MCPcopy Create free account
hub / github.com/camilamaia/jornada-big-tech / Solution

Class Solution

leetcode/src/TwoSumII.java:2–20  ·  view source on GitHub ↗

Problem: https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/

Source from the content-addressed store, hash-verified

1/** Problem: https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ */
2class 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected