from collections import deque
def solution(bridge_length, weight, truck_weights):
answer = 0
q = [0] * bridge_length
q = deque(q)
truck_weights = deque(truck_weights)
while q:
answer += 1
q.popleft()
if truck_weights:
if sum(q) + truck_weights[0] <= weight:
front = truck_weights.popleft()
q.append(front)
else:
q.append(0)
return answer
다른 풀이
def solution(bridge_length, weight, truck_weights):
time = 0
q = [0] * bridge_length
while q:
time += 1
q.pop(0)
if truck_weights:
if sum(q) + truck_weights[0] <= weight:
q.append(truck_weights.pop(0))
else:
q.append(0)
return time
programmers.co.kr/learn/courses/30/lessons/42583
'알고리즘 > 프로그래머스(Python)' 카테고리의 다른 글
힙 - 더 맵게 / 파이썬 (0) | 2020.11.05 |
---|---|
큐 - 프린터 / 파이썬 (0) | 2020.11.04 |
스택 - 기능개발 / 파이썬 (0) | 2020.11.03 |
스택 - 주식가격 / 파이썬 (0) | 2020.11.03 |
bfs - 단어 변환 / 파이썬 (0) | 2020.11.02 |