Very concise java solution


  • 0
    S
    public class Solution extends Reader4 {
       public int read(char[] buf, int n) {
        int pos = 0;
        int cur = 0;
        char[] tmp = new char[4];
        cur = read4(tmp);
        while(cur != 0 && pos < n) {
            int limit = Math.min(cur, n-pos);
            for(int i = 0; i < limit; i++) {
                buf[pos++] = tmp[i];
            }
            cur = read4(tmp);
        }
    
        return pos;
    }
    

    }


Log in to reply
 

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