★DEQUE★다리를 지나는 트럭[프로그래머스]
2022. 11. 29. 10:40
728x90
반응형
https://school.programmers.co.kr/learn/courses/30/lessons/42583
from collections import deque
def solution(bridge_length, weight, truck_weights):
answer = 0
bridge = deque(0 for _ in range(bridge_length))
# print(bridge)
truck_weights = deque(truck_weights)
while bridge:
answer += 1
bridge.popleft()
if truck_weights:
if sum(bridge) + truck_weights[0] <= weight:
t = truck_weights.popleft()
print("t: {}".format(t))
bridge.append(t)
else:
bridge.append(0)
return answer
print(solution(2, 10, [7, 4, 5, 6]), 8)
print(solution(100, 100, [10]), 101)
print(solution(100, 100, [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]), 110)
728x90
반응형
'Python(프로그래머스) > 스택,큐' 카테고리의 다른 글
★DEQUE★split()★괄호 회전하기[프로그래머스] (0) | 2023.04.26 |
---|---|
★VER3.0★Deque★문자열슬라이싱★같은 숫자는 싫어[프로그래머스] (1) | 2023.01.03 |
★DEQUE★enumerate★프린터[프로그래머스] (0) | 2022.11.19 |
VER2.0★DEL★DEQUE★기능개발[프로그래머스] (0) | 2022.11.19 |
★STACK★올바른 괄호[프로그래머스] (0) | 2022.11.18 |