본문 바로가기

CodingTest/Level2

[연습] 코딩테스트 - 다리를 지나는 트럭

코딩테스트 연습

  • programmers.co.kr
  • 다리를 지나는 트럭

 


 

def solution(bridge_length, weight, truck_weights):
    tmp_list = []
    cnt_list = []
    t = 0

    while 1:
        if truck_weights == [] and tmp_list == [] and cnt_list == []:
            break
        t += 1

        if cnt_list != [] and cnt_list[0] == bridge_length:
            cnt_list.pop(0)
            tmp_list.pop(0)
        if truck_weights != []:
            if (sum(tmp_list) + truck_weights[0]) <= weight:
                tmp_list += [truck_weights.pop(0)]
                cnt_list += [0]

        cnt_list = [x+1 for x in cnt_list]

    return (t)

    #print(t)



solution(2,    10,    [7,4,5,6])    
solution(100,100,[10])
solution(100,100,[10,10,10,10,10,10,10,10,10,10])
반응형