easy to understand


  • 0

    public static int[] twoSum(int[] numbers, int target) {
    int res[] = new int[2];
    int low = 0;int high = numbers.length-1;
    while(low < high){
    if (target>numbers[low]+numbers[high]) {
    low++;
    }else if (target<numbers[low]+numbers[high]) {
    high--;
    }else {
    res[0] = low+1;
    res[1] = high+1;
    break;
    }
    }
    return res;
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.