Description
https://leetcode.com/problems/task-scheduler/description/
Idea
The key of this problem is how to manipulate the order. First we should collect the count of each character.
Then we can image the box of n + 1 empty position which need to be filled by the given character. The solution chain should be contained of several box linked together(except for the last box).Each time when we are filling one box. We will fetch the character based on the count of the character in the priority queue.
In last iteration, there is no need to fill the n + 1 slots.
Solution
1 | import java.util.PriorityQueue; |