일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 시바견
- Convert Sorted List to Binary Search Tree
- attribute
- iterator
- Substring with Concatenation of All Words
- Python Code
- 파이썬
- Protocol
- data science
- Decorator
- 30. Substring with Concatenation of All Words
- LeetCode
- concurrency
- 운영체제
- Regular Expression
- Python
- t1
- Class
- shiba
- DWG
- kaggle
- 프로그래머스
- 715. Range Module
- 43. Multiply Strings
- 컴퓨터의 구조
- 밴픽
- Python Implementation
- 109. Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- Generator
Archives
- Today
- Total
Scribbling
LeetCode: 1834. Single-Threaded CPU 본문
class Solution:
def getOrder(self, tasks: List[List[int]]) -> List[int]:
import heapq
ret = []
TaskHeap = []
WaitHeap = []
for idx, task in enumerate(tasks):
heapq.heappush(TaskHeap, (task[0], idx, task[1]))
curTime = 0
while True:
if not WaitHeap:
if not TaskHeap:
break
startTime, idx, processTime = heapq.heappop(TaskHeap)
heapq.heappush(WaitHeap, (processTime, idx, startTime))
while TaskHeap and TaskHeap[0][0] == startTime:
startTime, idx, processTime = heapq.heappop(TaskHeap)
heapq.heappush(WaitHeap, (processTime, idx, startTime))
curTime = startTime
processTime, idx, startTime = heapq.heappop(WaitHeap)
ret.append(idx)
curTime += processTime
while TaskHeap and TaskHeap[0][0] <= curTime:
startTime, idx, processTime = heapq.heappop(TaskHeap)
heapq.heappush(WaitHeap, (processTime, idx, startTime))
return ret
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 772. Basic Calculator III (0) | 2022.03.11 |
---|---|
LeetCode: 745. Prefix and Suffix Search (0) | 2022.03.10 |
LeetCode: 407. Trapping Rain Water II (0) | 2022.03.08 |
LeetCode: 1610. Maximum Number of Visible Points (0) | 2022.03.07 |
LeetCode: 1284. Minimum Number of Flips to Convert Binary Matrix to Zero Matrix (0) | 2022.03.04 |