항해 TIL
틀린 풀이
from collections import deque
import math
def solution(progresses, speeds):
days = deque()
for progress, speed in zip(progresses, speeds):
day = (100 - progress) / speed
days.append(round(day))
print(days)
answer = []
f = 0
while days:
cnt = 0
while True:
if days:
if days[0] <= f:
days.popleft()
cnt += 1
else:
break
else:
break
if cnt > 0:
answer.append(cnt)
f += 1
return answer
progresses = [95, 90, 99, 99, 80, 99]
speeds = [1, 1, 1, 1, 1, 1]
print(solution(progresses, speeds))
Python
복사
정답 풀이
import math
from collections import deque
def solution(progresses, speeds):
answer = []
days = deque()
for progress, speed in zip(progresses, speeds):
day = (100 - progress) / speed
day = math.ceil(day)
days.append(day)
print(days)
while days:
for i in range(len(days)):
if days[i] == 0:
continue
days[i] -= 1
if days and days[0] == 0:
cnt = 0
flag = True
while flag and days:
if days[0] == 0:
days.popleft()
cnt+=1
else:
flag = False
answer.append(cnt)
print(answer)
return answer
Python
복사
from collections import deque
def ceil(num):
if num - int(num) > 0:
return int(num + 1)
else:
return int(num)
def solution(progresses, speeds):
days = deque()
for progress, speed in zip(progresses, speeds):
day = (100 - progress) / speed
days.append(ceil(num=day))
print(days)
answer = []
f = 0
while days:
cnt = 0
while True:
if days:
if days[0] <= f:
days.popleft()
cnt += 1
else:
break
else:
break
if cnt > 0:
answer.append(cnt)
f += 1
return answer
Python
복사
math.ceil을 하게 되면 round처럼 애매하게 반올림을 하는 것이 아닌, 말 그대로 다음 정수를 반환하게 된다
math.ceil이 기억이 안날 수 있으니, 그대로 구현