easy Java


  • 0
    W

    public class Solution extends Reader4 {
    Queue<Character> q = new LinkedList<Character>();
    boolean eof = false;
    /**
    * @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) {
    if(n==0||(q.size()==0&&eof==true))return 0;
    int cnt=0;
    while(cnt<n)
    {
    if(q.size()==0&&!eof)
    {
    char[]temp = new char[4];
    int get = read4(temp);
    if(get<4)
    {
    eof=true;
    }
    for(int i =0;i<get;++i)q.add(temp[i]);
    }
    if((eof&&q.size()==0))return cnt;
    buf[cnt++]=q.remove();

        }
        return cnt;
    }
    

    }


Log in to reply
 

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