| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- DWG
- 109. Convert Sorted List to Binary Search Tree
- Regular Expression
- 30. Substring with Concatenation of All Words
- Python Implementation
- 43. Multiply Strings
- 밴픽
- 프로그래머스
- shiba
- 315. Count of Smaller Numbers After Self
- LeetCode
- Decorator
- 파이썬
- concurrency
- data science
- kaggle
- iterator
- 시바견
- Python
- attribute
- 715. Range Module
- t1
- Convert Sorted List to Binary Search Tree
- Class
- 컴퓨터의 구조
- Generator
- Substring with Concatenation of All Words
- Python Code
- 운영체제
- Protocol
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 |