A more straightforward way instead of count the remaining


  • 0
    D

    A more straightforward way instead of count the remaining

    public class Solution extends Reader4 {
    /**
    * @param buf Destination buffer
    * @param n Maximum number of characters to read
    * @return The number of characters read
    */
    public int read(char[] buf, int n) {
    int total = 0;
    char[] buffer = new char[4];
    while(total < n){
    int count = read4(buffer);
    if(count == 0) break;
    for(int i = 0; i < count && total < n; i++){
    buf[total++] = buffer[i];
    }
    }
    return total;
    }
    }


Log in to reply
 

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