풀면 쉬운 문제
progresses와 speeds를 동시에에 순회 O(N) 소요
def solution(progresses, speeds):
answer = []
days = 1
count = 0
while len(progresses) > 0 :
if (progresses[0] + speeds[0] * days) >= 100 :
count += 1
progresses.pop(0)
speeds.pop(0)
else :
if count > 0 :
answer.append(count)
count = 0
days += 1
answer.append(count)
return answer
사실 list queue를 이용하는 방법은 무조건 O(N) 이 소요되기 때문에
collections.deque를 이용하는 것이 더 좋음
from collections import deque
def solution(progresses, speeds):
answer = []
days = 1
count = 0
pr = deque(progresses)
sp = deque(speeds)
while pr :
if (pr[0] + sp[0] * days) >= 100 :
count += 1
pr.popleft()
sp.popleft()
else :
if count > 0 :
answer.append(count)
count = 0
days += 1
answer.append(count)
return answer