Simple Java Code


  • 0
    F
    public class Solution extends Reader4 {
    
        private char[] buf4 = new char[ 4 ];
        private int buf4Ptr = 0;
        private int buf4Size = 0;
        
        public int read(char[] buf, int n) {
            int total = 0;
            
            for(; buf4Ptr<buf4Size && total<n; buf[ total++ ] = buf4[ buf4Ptr++ ]);  //Read the remaining characters in the 4-byte buffer
            if(total < n) {
                do {
                    buf4Size = read4(buf4);
                    for(buf4Ptr = 0; buf4Ptr<buf4Size && total<n; buf[ total++ ] = buf4[ buf4Ptr++ ]);
                } while(buf4Size==4 && total<n);
            }
            
            return total;
        }
    }
    

Log in to reply
 

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