BootyFul java solution


  • 0
    H
        Deque<Character> q = new LinkedList<>(); 
        public int read(char[] buf, int n) {
            int cnt = 0;
            int last = 4;
            char[] temp = new char[4];
            
            while(!q.isEmpty() && cnt<n)
                buf[cnt++] = q.poll();
            
            while(cnt<n && last==4){
                last = read4(temp);
                for(int i=0; i<last; i++){
                    if(cnt<n) buf[cnt++] = temp[i];
                    else q.add(temp[i]); 
                }
            }
            return cnt;
        }
    

Log in to reply
 

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