알고리즘 - 기능개발 python

pyhoo·2020년 9월 11일
0

Algorithm

목록 보기
2/11
post-thumbnail

import math
def solution(progresses, speeds):
    answer = list()
    # 남은 작업량 리스트에 저장 => list comprehension
    rest = [math.ceil((100 - p) / s) for p, s in zip(progresses, speeds)]

    count = 1
    max_rest = rest[0]

    for i in range(1, len(rest)):
        if max_rest >= rest[i]:
            count += 1
        else:
            answer.append(count)
            max_rest = rest[i]
            count = 1
    answer.append(count)
    return answer

원래는 rest 배열 정의부분을

    for i in zip(progresses,speeds):
        rest.append(math.ceil((100-i[0])/i[1]))

이런식으로 짰는데, list comprehension으로 more 깔끔하게 짤 수 있었다.

0개의 댓글