본문 바로가기

알고리즘

프로그래머스 Level 2 기능개발 - Python

import math

def solution(progresses, speeds):
    answer = []
    result = []

    num = len(progresses)
    
    # 0 ~ num-1
    for i in range(num):
        temp = 100 - progresses[i] 
        temp = temp / speeds[i]
        temp = math.ceil(temp)
        result.append(temp)
    
    n = 1
    
    # 같은 number로 
    for i in range(1, len(result)):
        if result[i-1] > result[i]:
            result[i] = result[i-1]
    
    
    
    for i in range(1, len(result)):
        if result[i-1] >= result[i]:
            n += 1
        else:
            answer.append(n)
            n = 1
            
    answer.append(n)
            
            
    
    return answer

 

'알고리즘' 카테고리의 다른 글