본문 바로가기

Problem Solving/Programmers - Python

[Python | 파이썬] 기능개발 (프로그래머스 STACK/QUEUE)

[Python | 파이썬] 기능개발 (프로그래머스 STACK/QUEUE)

 

 

앞에서부터 배포할 수 있으므로 현재까지 배포된 기능의 개수를 세는 변수 count와 현재 시행에서 배포될 수 있는 기능을 세는 변수 tmpcount를 선언한다. 그리고 전체 기능이 배포가 완료될까지 반복하면서, 각 index의 progresses[i]를 speeds[i]를 더한 값으로 갱신한다. 그리고 하나라도 100이 넘는다면 배포가 되는 것이므로 answer에 tmpcount를 추가해준다.

더보기
def solution(progresses, speeds):
    answer = []
    length = len(progresses)
    count = 0
    tmpcount = 0
    while count != length:
        tmpcount = 0
        for i in range(count, len(progresses)):
            progresses[i] += speeds[i]
        for i in range(count, len(progresses)):
            if progresses[i] >= 100:
                count += 1
                tmpcount += 1
            else:
                break
        if tmpcount != 0:
            answer.append(tmpcount)
    return answer

https://programmers.co.kr/learn/courses/30/lessons/42586

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr