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