📌문제
https://programmers.co.kr/learn/courses/30/lessons/42586
🎖️난이도
Level 2
✔️풀이
# sol1
def solution(progresses, speeds):
import math
answer = []
l = len(progresses)
left_days = [math.ceil((100-progresses[i])/speeds[i]) for i in range(l)]
baepo_num = 1
tmp_max = left_days[0]
for item in left_days[1:]:
if item > tmp_max: # 같아도 continue
answer.append(baepo_num)
tmp_max = item
baepo_num = 1
continue
baepo_num += 1
answer.append(baepo_num)
return answer
# sol2
from collections import deque
import math
def solution(progresses, speeds):
answer = []
left_days = deque([math.ceil((100 - progresses[i]) / speeds[i]) for i in range(len(progresses))])
cnt = 0
tmp_days = left_days[0]
while left_days:
if left_days[0] <= tmp_days:
left_days.popleft()
cnt += 1
continue
else:
answer.append(cnt)
cnt = 0
tmp_days = left_days[0]
answer.append(cnt)
return answer
'[ 알고리즘 ] > Stack, Queue' 카테고리의 다른 글
[프로그래머스/C++] 올바른 괄호 (0) | 2022.10.10 |
---|---|
[프로그래머스] 다리를 지나는 트럭 (0) | 2022.06.29 |
[프로그래머스] 프린터 (0) | 2022.06.29 |