Simple and short java solution


  • 1
    K
    public class Solution extends Reader4 {
        char[] buf4 = new char[4];
        int i4 = 0, n4 = 0;
        public int read(char[] buf, int n) {
            int i = 0;
            while (i < n) {
                if(i4 == n4) {
                    i4 = 0;
                    n4 = read4(buf4);
                    if(n4 == 0) {
                        break;
                    }
                }
                buf[i++] = buf4[i4++];
            }
            return i;
        }
    }
    

Log in to reply
 

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