231023 기능개발

Jongleee·2023년 10월 23일
0

TIL

목록 보기
397/737
public int[] solution(int[] progresses, int[] speeds) {
	Queue<Integer> daysToComplete = new LinkedList<>();

	for (int i = 0; i < speeds.length; i++) {
		int remainingDays = (100 - progresses[i]) / speeds[i];
		if ((100 - progresses[i]) % speeds[i] != 0) {
			remainingDays++;
		}
		daysToComplete.offer(remainingDays);
	}

	List<Integer> resultList = new ArrayList<>();
	int currentTask = daysToComplete.poll();
	int count = 1;

	while (!daysToComplete.isEmpty()) {
		int nextTask = daysToComplete.poll();
		if (currentTask >= nextTask) {
			count++;
		} else {
			resultList.add(count);
			count = 1;
			currentTask = nextTask;
		}
	}

	resultList.add(count);

	int[] result = new int[resultList.size()];
	for (int i = 0; i < resultList.size(); i++) {
		result[i] = resultList.get(i);
	}

	return result;
}

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

0개의 댓글