Java concise 5 line code.


  • 0
    M
        public int read(char[] buf, int n) {
            char[] tmpBuf=new char[4];
            int sum=0,left=0;
            
            while((left=read4(tmpBuf))>=4) for(int i=0;i<4;i++) buf[sum++]=tmpBuf[i];
            
            for(int i=0;i<left;i++) buf[sum++]=tmpBuf[i];
            
            return Math.min(n,sum);
        }
    

Log in to reply
 

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