Skip to content

Commit d68429f

Browse files
authored
Merge pull request #708 from AlgorithmWithGod/khj20006
[20250821] PGM / LV3 / 광고 삽입 / 혁준
2 parents 15188ae + f7d25dd commit d68429f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
```java
2+
class Solution {
3+
public int convertTime(String time) {
4+
String[] args = time.split(":");
5+
return Integer.parseInt(args[0])*3600 + Integer.parseInt(args[1])*60 + Integer.parseInt(args[2]);
6+
}
7+
8+
public String solution(String play_time, String adv_time, String[] logs) {
9+
// 1. imos
10+
int N = convertTime(play_time), M = convertTime(adv_time);
11+
long[] arr = new long[N+2];
12+
for(String log : logs) {
13+
String[] args = log.split("-");
14+
int start = convertTime(args[0]), end = convertTime(args[1]);
15+
arr[start]++;
16+
arr[end]--;
17+
}
18+
19+
// 2. find
20+
long s = arr[0];
21+
long[] b = new long[N+1];
22+
b[0] = s;
23+
for(int i=1;i<=N;i++) {
24+
s += arr[i];
25+
b[i] = s + b[i-1];
26+
}
27+
28+
int ans = 0;
29+
long max = b[M];
30+
for(int i=1;i+M-1<=N;i++) if(b[i+M-1]-b[i-1] > max) {
31+
max = b[i+M-1]-b[i-1];
32+
ans = i;
33+
}
34+
35+
int hour = ans / 3600;
36+
ans %= 3600;
37+
int minute = ans / 60;
38+
ans %= 60;
39+
int second = ans;
40+
41+
String result = "";
42+
if(hour < 10) result += "0";
43+
result += Integer.toString(hour) + ":";
44+
if(minute < 10) result += "0";
45+
result += Integer.toString(minute) + ":";
46+
if(second < 10) result += "0";
47+
result += Integer.toString(second);
48+
49+
return result;
50+
51+
}
52+
}
53+
```

0 commit comments

Comments
 (0)