231104 셔틀버스

Jongleee·2023년 11월 4일
0

TIL

목록 보기
408/737
public String solution(int n, int t, int m, String[] timetable) {
	int busTime = 9 * 60;
	int busCount = 0;
	int lastCrewTime = 0;

	PriorityQueue<Integer> crew = new PriorityQueue<>();
	for (String time : timetable) {
		crew.add(timeToInteger(time));
	}

	while (busCount < n) {
		if (busCount != 0)
			busTime += t;
		int cnt = 0;

		while (!crew.isEmpty() && cnt < m) {
			if (crew.peek() > busTime)
				break;
			if (busCount == n - 1 && cnt == m - 1) {
				lastCrewTime = (crew.poll() - 1);
				return String.format("%02d:%02d", lastCrewTime / 60, lastCrewTime % 60);
			}
			crew.poll();
			cnt++;
		}
		busCount++;
	}
	return String.format("%02d:%02d", busTime / 60, busTime % 60);
}

public int timeToInteger(String time) {
	String[] times = time.split(":");
	return Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]);
}

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

0개의 댓글