My very simple Java solution.


  • 0
    K
    public class Solution extends Reader4 
    {
        public int read(char[] buf, int n) 
        {
            char[] temp = new char[4];
            int total = 0, count = 1;
            
            while(total < n+4 && count > 0)
            {
                count = read4(temp);
                for(int j=0; j<count && total < n; j++)
                    buf[total++] = temp[j];
            }
            return total;
        }
    }
    

Log in to reply
 

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