[プログラマ]機能の開発(JAVA)


質問する


https://programmers.co.kr/learn/courses/30/lessons/42586

マイコード

class Program{
	int progress;
	int speed;
	public Program(int progress, int speed) {
		this.progress = progress;
		this.speed = speed;
	}
}
public List<Integer> solution(int[] progresses, int[] speeds) {
	List<Integer> rlt = new ArrayList<>();
	//2
	Queue<Program> queue = new LinkedList<>();
	for(int i=0; i<progresses.length; i++) {
		queue.offer(new Program(progresses[i], speeds[i]));
	}
    	//3
	while(!queue.isEmpty()){
		int count = 0;
        	//4
		for(int i=0; i<queue.size(); i++) {
			Program temp = queue.poll();
			temp.progress += temp.speed;
			queue.offer(temp);
		}
		//5
		while(queue.size()>0) {
			if(queue.peek().progress >= 100) {
				queue.poll();
				count++;
			}else {
				break;
			}
		}
        	//6
		if(count >0)
			rlt.add(count);
		
	}
	
	return rlt;
}

に答える

  • プログラムクラスは、生成者パラメータとしてタスクの進捗とタスク速度を使用する
  • を定義します.
  • ループ文には、プログラムオブジェクトがキューに含まれます.
  • キューが空になるまで繰り返し文
  • を実行
  • プログラムの進捗を繰り返し、作業速度を向上させる.
  • タスクを完了したプログラムは、キューからcountを減算して増加します.
  • で増加したcount数に基づいて結果リストを入力します.