Bug in 167. Two Sum II


  • 0
    T

    When I submitted my code (version1), it got the time exceed error.

        int lowIndex = 0;
        int highIndex = numbers.length - 1;
        while(numbers[lowIndex] + numbers[highIndex] != target) {
            if(numbers[lowIndex] + numbers[highIndex] > target) {
                highIndex--;
            }
            else {
                lowIndex++;
            }
        }
        return new int[]{lowIndex + 1, highIndex + 1};
    

    However, when I changed the variable names into r,h, it is get accepted. (below version2)

        int l = 0;
        int h = numbers.length - 1;
        while(numbers[l] + numbers[h] != target) {
            if(numbers[l] + numbers[h] > target) {
                h--;
            }
            else {
                l++;
            }
        }
        return new int[]{l + 1, h + 1};
    

    Is this the bug on the LC?

    Regards,
    Tianbing


Log in to reply
 

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