Java Solution, easy to understand!!!!!


  • 0
        public int read(char[] buf, int n) {
            char[] temp = new char[4];
            int num = 4;
            int count = 0;
            while(num == 4 && count < n) {
                int t = read4(temp);
                num = t;
                for(int i = count; i < Math.min(n,count+t); i++) {
                    buf[i] = temp[i-count];
                }
                count = Math.min(n,count+t);
            }
            return count;
        }
    

Log in to reply
 

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