import java.util.*;
class Solution {
public String solution(int n, int t, int m, String[] timetable) {
List<Integer> wait = new ArrayList<>();
for (String time : timetable) {
String[] parts = time.split(":");
int minute = Integer.parseInt(parts[0]) * 60 + Integer.parseInt(parts[1]);
wait.add(minute);
}
Collections.sort(wait);
int crewIdx = 0;
int shuttleTime = 540; // 09:00 in minutes
int lastBoarded = 0;
for (int i = 0; i < n; i++) {
int count = 0;
while (crewIdx < wait.size() && wait.get(crewIdx) <= shuttleTime && count < m) {
lastBoarded = wait.get(crewIdx);
crewIdx++;
count++;
}
if (i == n - 1) {
// 마지막 셔틀
if (count == m) {
// 만석이면 마지막 탄 사람보다 1분 빨리 와야 함
return toTimeString(lastBoarded - 1);
} else {
// 자리 남았으면 도착 시간에 타면 됨
return toTimeString(shuttleTime);
}
}
shuttleTime += t;
}
return ""; // 도달 불가
}
private String toTimeString(int minutes) {
int hour = minutes / 60;
int min = minutes % 60;
return String.format("%02d:%02d", hour, min);
}
}
1. String.format("%02d:%02d", hour,min); stringformat으로 0채워주기
'기타 > 코딩테스트' 카테고리의 다른 글
| (코테) 프로그래머스_[3차] 파일명 정렬 (0) | 2025.08.06 |
|---|---|
| (코테) 프로그래머스_기둥과 보 설치 *시물레이션+구현 (3) | 2025.08.02 |
| (코테) 프로그래머스_[3차] 압축 *정렬 문자열 변환 (3) | 2025.07.30 |
| (코테) 프로그래머스_여행경로 *dfs 백트레킹 (3) | 2025.07.23 |
| (코테) 프로그래머스_섬 연결하기 *유니온 파인드 (3) | 2025.07.17 |