Skip to content

Instantly share code, notes, and snippets.

@yungyungGwon
Created November 11, 2021 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yungyungGwon/c24621a2696e603ff9fdecfe23425f3a to your computer and use it in GitHub Desktop.
Save yungyungGwon/c24621a2696e603ff9fdecfe23425f3a to your computer and use it in GitHub Desktop.
def solution(bridge_length, weight, truck_weights):
answer = 0
bridge = [0] * bridge_length; #bridg 리스트 다리 길이 만큼 초기화 하는 작업
bridgeWeight = 0
while True:
if len(truck_weights) == 0 and bridgeWeight == 0:
break #건널 트럭이 없으면 while문 나가기
answer += 1
if bridge[0] != 0:
bridgeWeight -= bridge[0]
del bridge[0] #del은 해당 인덱스 삭제 함수
nextNum = 0
if truck_weights:
if bridgeWeight + truck_weights[0] <= weight:
nextNum = truck_weights[0]
bridgeWeight += truck_weights[0]
del truck_weights[0]
bridge.append(nextNum)
return answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment