Simple Java solution


  • 0
    H
    public int read(char[] buf, int n) {
            if (n == 0) return 0;
            int i = 0;
            while (true) {
                char[] smallBuffer = new char[4];
                int readNum = read4(smallBuffer);
                for (int j = 0; j < readNum; j++) {
                    buf[i] = smallBuffer[j];
                    i++;
                    if (i == n) return i;
                }
                if (readNum < 4) break;
            }
            return i;
        }
    

Log in to reply
 

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