import math
from collections import Counter
def solution(progresses, speeds):
date = [math.ceil((100-x)/y)for x, y in zip(progresses, speeds)]
stack = []
answer = []
for i in range(len(date)):
if len(stack) == 0:
stack.append(date[i])
answer.append(date[i])
else:
stack.append(date[i])
if stack[len(stack)-1] >= stack[len(stack)-2]:
answer.append(date[i])
else:
stack.pop()
answer.append(stack[len(stack)-1])
result = list(Counter(answer).values())
return result
풀이과정
- 필요한 작업 일수를 배열로 만들어 date에 저장한다.
- date의 길이만큼 반복문을 돌리면서 stack[-1]와 stack[-2] 를 비교한다.
- stack[-1]이 stack[-2]보다 작으면 pop한 후, 원래의 값을 넣는다.
- 나온 배열 원소의 갯수를 세서 배열로 반환한다.
새로 배운 내용
import math
math.floor() // 소수점 이하 버림
math.ceil() // 소수점 이하 올림
math.round() // 소수점 이하 반올림