🖇️ 문제 링크
⌨️ 코드
class Solution {
public String solution(String play_time, String adv_time, String[] logs) {
int[] time = new int[100 * 60 * 60];
int play = getSecond(play_time);
int adv = getSecond(adv_time);
for(String log : logs) {
int s = getSecond(log.split("-")[0]);
int e = getSecond(log.split("-")[1]);
for(int i = s; i < e; i++)
time[i] += 1;
}
long cur = 0;
for(int i = 0; i < adv; i++)
cur += time[i];
long max = cur;
int ret = 0;
for(int i = adv; i < play; i++) {
cur = cur + time[i] - time[i - adv];
if(cur > max) {
max = cur;
ret = i - adv + 1;
}
}
return String.format("%02d:%02d:%02d", ret / (60 * 60), (ret / 60) % 60, ret % 60);
}
public int getSecond(String s) {
return Integer.parseInt(s.split(":")[0]) * 3600
+ Integer.parseInt(s.split(":")[1]) * 60
+ Integer.parseInt(s.split(":")[2]);
}
}
Uploaded by Notion2Tistory v1.1.0