public int solution(int[] order) {
Queue<Integer> workingQueue = new LinkedList<>();
Stack<Integer> waitingStack = new Stack<>();
int cnt = 0;
for (int i = 0; i < order.length; i++) {
waitingStack.add(i + 1);
while (!waitingStack.isEmpty()) {
if (waitingStack.peek() == order[cnt]) {
workingQueue.offer(waitingStack.pop());
cnt++;
} else {
break;
}
}
}
return workingQueue.size();
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/131704