
😎코딩테스트 연습>스택/큐>기능개발
📘 문제풀이
import math
def solution(progresses, speeds):
answer = []
day = []
stack = []
for p, s in zip(progresses, speeds):
day.append(math.ceil((100-p)/s))
s = day[0]
for d in day:
if s >= d:
stack.append(d)
else:
s = d
answer.append(len(stack))
stack.clear()
stack.append(d)
if len(stack) != 0:
answer.append(len(stack))
return answer

📘 문제풀이2
import math
def solution(progresses, speeds):
answer = []
day = []
d1 = math.ceil((100-progresses[0])/speeds[0])
for p, s in zip(progresses, speeds):
d2 = math.ceil((100-p)/s)
if d1 >= d2:
day.append(d2)
else:
d1 = d2
answer.append(len(day))
day.clear()
day.append(d2)
if len(day) != 0:
answer.append(len(day))
return answer

쪼금 시간이 줄긴 했다
📘 문제풀이3
import math
def solution(progresses, speeds):
answer = []
cnt = 0
d1 = math.ceil((100-progresses[0])/speeds[0])
for p, s in zip(progresses, speeds):
d2 = math.ceil((100-p)/s)
if d1 >= d2:
cnt += 1
else:
answer.append(cnt)
d1 = d2
cnt = 1
answer.append(cnt)
return answer

리스트 추가 안하고 변수로 하면 더 빠를 줄 알았는데
그런 건 또 아난듯?