일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 영어공부
- 프로젝트
- 만화도
- realclass
- 30분
- 운동
- 월간
- Writing
- 매일
- 잡생각
- 미드시청
- 파비최
- 사이드
- 3줄정리
- 링피트
- 쓰릴오브파이트
- English
- FIT XR
- 개발자
- 리얼 클래스
- leetcode
- 읽기
- 화상영어
- 10분
- 스탭퍼
- 영어원서읽기
- Daily Challenge
- Problem Solving
- 뭐든
- 괜찮음
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/single-threaded-cpu/
Single-Threaded CPU - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
heap과 sort를 활용해서 풀면 된다.
운영체제 이론에서 비슷한걸 본 것 같은 느낌..
class Solution:
def getOrder(self, tasks: List[List[int]]) -> List[int]:
res = []
tasks = sorted([(t[0], t[1], i) for i, t in enumerate(tasks)])
i = 0
h = []
time = tasks[0][0]
while len(res) < len(tasks):
while (i < len(tasks)) and (tasks[i][0] <= time):
heapq.heappush(h, (tasks[i][1], tasks[i][2]))
i += 1
if h:
t_diff, original_index = heapq.heappop(h)
time += t_diff
res.append(original_index)
elif i < len(tasks):
time = tasks[i][0]
return res
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.12.31 |
---|---|
Today's Challenge (0) | 2022.12.30 |
Today's Challenge (0) | 2022.12.28 |
Today's Challenge (0) | 2022.12.27 |
Today's Challenge (0) | 2022.12.26 |
Comments