2018 KAKAO BLIND RECRUITMENT 추석 트래픽
유형
코드
class Solution {
class Log {
long start;
long end;
public Log(long start, long end) {
this.start = start;
this.end = end;
}
}
public int solution(String[] lines) {
Log[] logs = new Log[lines.length];
int logNum = lines.length;
for(int i = 0; i < logNum; i++) {
String[] temp = lines[i].split(" ");
long endTime = timeToMilisec(temp[1]);
long processingTime = (long)(Float.parseFloat(temp[2].substring(0, temp[2].length() - 1)) * 1000);
long startTime = endTime + 1 - processingTime;
logs[i] = new Log(startTime, endTime);
}
int max = 0;
for(int i = 0; i < logNum; i++) {
long startTime = logs[i].end;
long endTime = startTime + 1000;
int cnt = 0;
for(int j = 0; j < logNum; j++) {
if(logs[j].start >= endTime || logs[j].end < startTime) {
continue;
}
cnt++;
}
if(cnt > max) {
max = cnt;
}
}
return max;
}
long timeToMilisec(String time) {
String[] temp = time.split("\\.");
long milisec = Long.parseLong(temp[1]);
temp = temp[0].split(":");
long hour = Long.parseLong(temp[0]);
long min = Long.parseLong(temp[1]);
long sec = Long.parseLong(temp[2]);
milisec += (hour * 60 * 60 + min * 60 + sec) * 1000;
return milisec;
}
}