티스토리 뷰
반응형
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package KAKAO; | |
public class AD_Insert { | |
public static void main(String[] args) { | |
String play_time = "02:03:55"; | |
String adv_time = "00:14:15"; | |
String[] logs = {"01:20:15-01:45:14", "00:40:31-01:00:00", "00:25:50-00:48:29", "01:30:59-01:53:29", "01:37:44-02:02:30"}; | |
System.out.println(solution(play_time, adv_time, logs)); | |
} | |
public static String solution(String play_time, String adv_time, String[] logs) { | |
int PT = convert(play_time); | |
int AT = convert(adv_time); | |
int[] LT = new int[100 * 3600]; | |
for (String log : logs) { | |
int start = convert(log.substring(0, 8)); | |
int end = convert(log.substring(9, 17)); | |
for (int i = start; i < end; i++) { | |
LT[i] += 1; | |
} | |
} | |
long currenttime = 0; | |
for (int i = 0; i < AT; i++) { | |
currenttime += LT[i]; | |
} | |
long maxsum = currenttime; | |
int maxidx = 0; | |
for (int i = AT; i < PT; i++) { | |
currenttime = currenttime + LT[i] - LT[i - AT]; | |
if (currenttime > maxsum) { | |
maxsum = currenttime; | |
maxidx = i - AT + 1; | |
} | |
} | |
return String.format("%02d:%02d:%02d", maxidx / 3600, maxidx / 60 % 60, maxidx % 60); | |
} | |
public static int convert(String time){ | |
String[] nums = time.split(":"); | |
return Integer.parseInt(nums[0]) * 60 * 60 + | |
Integer.parseInt(nums[1]) * 60 + | |
Integer.parseInt(nums[2]); | |
} | |
} | |

반응형
'알고리즘 > 프로그래머스' 카테고리의 다른 글
2018 카카오 비밀지도 (0) | 2021.04.20 |
---|---|
2019 카카오 후보키 (0) | 2021.04.20 |
2019 카카오 오픈채팅 (0) | 2021.04.20 |
2019 카카오 실패율 (0) | 2021.04.20 |
[2021 카카오] 합승 택시요금 (0) | 2021.03.29 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- C언어
- kakao
- Solid
- Matlab
- 디자인패턴
- Spring
- JPA
- CS
- 자바
- 자격증
- Algorithm
- 스프링
- 백준
- java
- ajax
- interview
- 면접
- nginx
- springboot
- 릿코드
- 수학
- 스프링부트
- 알고리즘
- spring-cloud
- 프로그래머스
- 그래프
- security
- OOP
- 매트랩
- docker
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함