일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- LeetCode
- attribute
- 컴퓨터의 구조
- 315. Count of Smaller Numbers After Self
- Python Code
- 715. Range Module
- Protocol
- Python Implementation
- concurrency
- 운영체제
- Convert Sorted List to Binary Search Tree
- Regular Expression
- Python
- Decorator
- t1
- Generator
- 시바견
- 파이썬
- 밴픽
- 프로그래머스
- 30. Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- 109. Convert Sorted List to Binary Search Tree
- DWG
- 43. Multiply Strings
- data science
- Class
- shiba
- iterator
- kaggle
Archives
- Today
- Total
Scribbling
프로그래머스: 다리를 지나는 트럭 본문
from collections import deque
def solution(bridge_length, weight, truck_weights):
time, total_weight = 1, 0
q = deque()
truck_weights = deque(truck_weights)
while truck_weights:
if not q:
w = truck_weights.popleft()
q.append([time, w])
total_weight += w
else:
if q[0][0] + bridge_length == time:
total_weight -= q[0][1]
q.popleft()
w = truck_weights[0]
if total_weight + w <= weight:
w = truck_weights.popleft()
q.append([time, w])
total_weight += w
time += 1
return q[-1][0] + bridge_length
'Computer Science > Coding Test' 카테고리의 다른 글
프로그래머스: 더 맵게 (0) | 2021.10.16 |
---|---|
프로그래머스: 주식 가격 (0) | 2021.10.16 |
LeetCode: 96. Unique Binary Search Trees (0) | 2021.10.13 |
LeetCode: 95. Unique Binary Search Trees II (0) | 2021.10.13 |
LeetCode: 92. Reverse Linked List II (0) | 2021.10.12 |