-
-
Save yungyungGwon/c24621a2696e603ff9fdecfe23425f3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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