I just feel like my thinking method is a little bit different from what's posted here and it's accepted-java


  • 0
    C
    public class Solution extends Reader4 {
        /**
         * @param buf Destination buffer
         * @param n   Maximum number of characters to read
         * @return    The number of characters read
         */
        public int read(char[] buf, int n) {
            char[] temp=new char[4];
            int count=read4(temp);
            int j=0,i=0;
            while(count>0){
                while(i<count&&j<n){
                    buf[j++]=temp[i++];
                }
                if(j==n) return j;
                i=0;
                count=read4(temp);
            }
            return j;
            
        }
    }

Log in to reply
 

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