import java.util.Objects;
class Solution {
public int[] twoSum(int[] numbers, int target) {
if (Objects.isNull(numbers)) {
return null;
}
int l = 0;
int r = numbers.length - 1;
int[] result = new int[2];
while (l < r) {
int sum = numbers[l] + numbers[r];
if (sum == target) {
result[0] = l + 1;
result[1] = r + 1;
return result;
} else if (sum < target) {
++ l;
} else {
-- r;
}
}
return result;
}
}
转载于:https://blog.51cto.com/tianyiya/2172964