/ 코드 1 /
def solution(bridge_length, weight, truck_weights):
q=[0]*bridge_length
sec=0
while q:
sec+=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 sec
/ 코드 2 /
from collections import deque
def solution(bridge_length, weight, truck_weights):
bridge = deque(0 for _ in range(bridge_length))
total_weight = 0
step = 0
truck_weights.reverse()
while truck_weights:
total_weight -= bridge.popleft()
if total_weight + truck_weights[-1] > weight:
bridge.append(0)
else:
truck = truck_weights.pop()
bridge.append(truck)
total_weight += truck
step += 1
step += bridge_length
return step
'CodingTest > Programmers' 카테고리의 다른 글
[ 프로그래머스 ] 순위 검색 (0) | 2022.06.29 |
---|---|
[ 프로그래머스 ] 수식 최대화 (0) | 2022.06.29 |
[ 프로그래머스 ] 124 나라의 숫자 (0) | 2022.06.26 |
[ 프로그래머스 ] 타켓 넘버 < 다시 풀기 > (0) | 2022.06.25 |
[ 프로그래머스 ] 구명보트 (0) | 2022.06.25 |