What kind of wrong answer is this?


  • 1
    R

    Below is my code:

    public int read(char[] buf, int n) {
        if(n<=4)
            return Math.min(read4(buf),n);
            
        int count = n;
        int total = 0;
        int pos = 0;
        while(count>0){
            char[] tmp = new char[4];
            int curr = read4(tmp);
            
            int steps = Math.min(count,curr);
            
            count -= curr;
            total += curr;
            
            for(int i=0;i<steps;i++){
                buf[pos+i] = tmp[i];
            }
            pos += curr;
            if(curr<4){
                break;
            }
        }
        
        return total;
    }
    

    And the result of it is:

    Input:
    "1234567", 6

    Output:
    "123456"

    Expected:
    "123456"

    I do not see why this is wrong :/ Is it a bug in the test case?


Log in to reply
 

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