728x90
https://programmers.co.kr/learn/courses/30/lessons/17676
코딩테스트 연습 - [1차] 추석 트래픽
입력: [ "2016-09-15 20:59:57.421 0.351s", "2016-09-15 20:59:58.233 1.181s", "2016-09-15 20:59:58.299 0.8s", "2016-09-15 20:59:58.688 1.041s", "2016-09-15 20:59:59.591 1.412s", "2016-09-15 21:00:00.464 1.466s", "2016-09-15 21:00:00.741 1.581s", "2016-09-1
programmers.co.kr
코드 :
def solution(lines):
answer = 0
start_time = []
end_time = []
for t in lines:
time = t.split(" ")
start_time.append(get_start_time(time[1], time[2]))
end_time.append(get_time(time[1]))
for i in range(len(lines)):
cnt = 0
cur_end_time = end_time[i]
# i번째는 현재 자신의 시작시간이고, i 이하는 그 이전의 시작시간이므로 카운트 할 필요가 없다.
for j in range(i, len(lines)):
if cur_end_time > start_time[j] - 1000:
cnt += 1
answer = max(answer, cnt)
return answer
def get_time(time):
hour = int(time[:2]) * 3600
minute = int(time[3:5]) * 60
second = int(time[6:8])
millisecond = int(time[9:])
return (hour + minute + second) * 1000 + millisecond
def get_start_time(time, duration_time):
n_time = duration_time[:-1]
int_duration_time = int(float(n_time) * 1000)
return get_time(time) - int_duration_time + 1
밀리세컨드 단위로 시간을 변경한다.
시작시간은 (끝나는 시간 - 지속시간 +1 )이다.
참고 블로그 :
[프로그래머스] 추석 트래픽 (python/파이썬)
프로그래머스 레벨3 추석 트래픽 문제
velog.io
반응형
'알고리즘 > 프로그래머스문제풀이' 카테고리의 다른 글
[Python/프로그래머스]양궁대회_Bfs (1) | 2022.09.19 |
---|---|
[Python/프로그래머스]k진수에서 소수 개수 구하기 (0) | 2022.09.19 |
[Python/프로그래머스]메뉴 리뉴얼 (0) | 2022.06.29 |
[Python/프로그래머스] 숫자 문자열과 영단어 (Level 1) (0) | 2022.06.29 |
[Python/프로그래머스]오픈채팅방 (0) | 2022.06.28 |