Two Sum II - Input array is sorted 2021-07-08 01:56

Problem Description

public int[] twoSum(int[] numbers, int target) {
    int[] resArray = new int[2];
    int begin = 0;
    int end = numbers.length - 1;
    while (begin <= end) {
        int res = numbers[begin] + numbers[end];
        if (res > target) {
            end--;
            continue;
        }
        if (res < target) {
            begin++;
            continue;
        }
        resArray[0] = begin + 1;
        resArray[1] = end + 1;
        break;
    }
    return resArray;
}
Runtime Memory
0 ms 38.8 MB

henryxi leetcode list

EOF