프로그래머스. 다리를 지나는 트럭 파이썬 풀이

minan·2021년 6월 22일
0

프로그래머스

목록 보기
28/92

프로그래머스. 스택/큐. Level 2.다리를 지나는 트럭 파이썬 풀이

문제링크 https://programmers.co.kr/learn/courses/30/lessons/42583

from collections import deque

def solution(bridge_length, weight, truck_weights):
    progress = [0] * bridge_length
    
    time = 0
    
    while truck_weights:
        time += 1
        progress.pop(0)            
            
        if sum(progress) + truck_weights[0] <= weight:
            progress.append(truck_weights.pop(0))
        else:
            progress.append(0)  
                   
    return time + len(progress)
profile
https://github.com/minhaaan

0개의 댓글