public int solution(String[][] bookTimeSlots) {
int[] roomUsage = new int[1449];
for (String[] timeSlot : bookTimeSlots) {
int startTime = convertToMinutes(timeSlot[0]);
int endTime = convertToMinutes(timeSlot[1]) + 9;
incrementRoomUsage(roomUsage, startTime, endTime);
}
return maxRoomUsage(roomUsage);
}
public int convertToMinutes(String time) {
int hours = Integer.parseInt(time.substring(0, 2));
int minutes = Integer.parseInt(time.substring(3, 5));
return (hours * 60) + minutes;
}
public void incrementRoomUsage(int[] roomUsage, int startTime, int endTime) {
for (int i = startTime; i <= endTime; i++) {
roomUsage[i]++;
}
}
public int maxRoomUsage(int[] roomUsage) {
return Arrays.stream(roomUsage).max().getAsInt();
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/155651