[プログラマー/queue/level 2]機能の開発
[プログラマ]機能の開発
日ごとに追加を行い、最前線の作業が完了しているかを確認します.
前の が完了したら、 前の作業が完了していない場合は、コマンドを発行します. 作業があれば、
1.問題の説明
前の
완료한 작업은 큐에서 제거
と다음 작업의 완료 여부
を確認してください.일자(day)를 증가
.2.トラブルシューティングコード
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
ArrayList<Integer> answerList = new ArrayList<>();
Queue<Work> queue = new LinkedList<>();
for (int i = 0; i < progresses.length; i++) {
queue.offer(new Work(progresses[i], speeds[i]));
}
int days = 1;
while (!queue.isEmpty()) {
int cnt = 0;
while (!queue.isEmpty()) {
Work work = queue.peek();
if (!work.isDone(days)) {
break;
}
queue.poll();
cnt++;
}
if (cnt > 0) {
answerList.add(cnt);
}
days++;
}
return answerList.stream().mapToInt(i -> i).toArray();
}
}
class Work {
private int progress;
private int speed;
Work(int progress, int speed) {
this.progress = progress;
this.speed = speed;
}
public boolean isDone(int days) {
return this.progress + (days * speed) >= 100;
}
}
Reference
この問題について([プログラマー/queue/level 2]機能の開発), 我々は、より多くの情報をここで見つけました https://velog.io/@pbg0205/프로그래머스queuelevel2-기능-개발テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol