public static int getTotalTimeList(List<Character> tasks, int cooldown) {
        // window size is cooldown, 
        // using linkedlists to record events time,
        // lists may be sparse that we only record events hour, not waiting hours
        
        // time for the events in the window
        List<Integer> ci = new LinkedList<>();
        
        // characters in the window
        List<Character>cc = new LinkedList<>();
        
        // ct the time for the current task
        int ct=0;
        
        // process each event 
        for (Character c: tasks) {
            // check whether there is conflict in the window
            ListIterator<Integer> iter1=ci.listIterator();
            ListIterator<Character> iter2=cc.listIterator();
            boolean delay=false;
            for (;iter2.hasNext();) {
                int t=iter1.next();
                if (iter2.next().equals(c)) {
                    delay=true;
                    ct= t+cooldown+1;
                    break;
                }
            }
            
            // no conflict, so increase ct by 1
            if (!delay) ++ct;
            
            // we update lists. delete all events happened earlier than ct-cooldown 
            iter1=ci.listIterator();
            iter2=cc.listIterator();
            for (;iter2.hasNext();) {
                int t=iter1.next();
                iter2.next();
                if (t>ct-cooldown) break;
                iter1.remove();
                iter2.remove();
            }
            
            // adding current event time, and character(event) to the lists
            ci.add(ct);
            cc.add(c);
        }
        
        return ct;
	}