Concise Java Solution


  • 0
        private char[] cache=new char[4];
        private int count=0;
        private int pos=0;
        
        public int read(char[] buf, int n) {
            int curIdx=0;
            read();
            while(curIdx<n && pos!=count)
            {
                    buf[curIdx++]=cache[pos++];
                    read();
            }
            return Math.min(curIdx,n);
        }
        
        public void read()
        {
            if(pos<count) return;
            count=read4(cache);
            pos=0;
        }
    

Log in to reply
 

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