[프로그래머스] 스택/큐 - 다리를 지나는 트럭 (Level 2)

imyo·2020년 9월 14일
0

알고리즘

목록 보기
3/39
post-thumbnail

다리를 지나는 트럭


Python Code

def solution(bridge_length, weight, truck_weights):
    answer = 0
    count = []  #각각의 트럭이 다리를 건넌 시간
    temp = []   #현재 다리 위에 있는 트럭
    while True:
        print(answer, temp, count, truck_weights)
        for i in count:
            if i == bridge_length:
                temp.pop(0)
                count.pop(0)
                
        if truck_weights:  
            if not temp or (temp and sum(temp)+truck_weights[0] <= weight):
                temp.append(truck_weights.pop(0))
                count.append(0)
            
        answer += 1
        count = [i + 1 for i in count]
        
        if not truck_weights and not temp:
            break
        
    return answer
profile
(●⁰౪⁰●)

0개의 댓글