Simple Java solution


  • 0
    S
        public int read(char[] buf, int n) {
            char []tbuf = new char[4];
            int i=0;
            for(; i < n;) {
                int count = read4(tbuf);
                if(count == 0) break; // eof, so end reading
                for(int j=0; j < count && i < n; j++,i++)
                    buf[i] = tbuf[j];
            }
            return i;
        }
    

Log in to reply
 

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