Skip to content

Commit d765fcf

Browse files
committedApr 30, 2021
2021-04-30
1 parent ad99e6d commit d765fcf

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
 
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Solution(object):
2+
def getOrder(self, tasks):
3+
"""
4+
:type tasks: List[List[int]]
5+
:rtype: List[int]
6+
"""
7+
from heapq import *
8+
if not tasks:
9+
return []
10+
11+
tasks = [(pair[1], index, pair[0]) for index, pair in enumerate(tasks)] # 打包原始下标
12+
tasks.sort(key = lambda x: x[2]) # 按入队时间排序
13+
14+
next_task_id = 0 # 下一项要干的工作
15+
cur_time = tasks[0][2]
16+
min_heap = []
17+
res = []
18+
while next_task_id < len(tasks) or min_heap:
19+
while next_task_id < len(tasks) and tasks[next_task_id][2] <= cur_time:
20+
# 入队所有已经可以开始干的工作
21+
heappush(min_heap, tasks[next_task_id])
22+
next_task_id += 1
23+
24+
# 开始工作
25+
if not min_heap:
26+
# 直接跳到下一个有效时间
27+
cur_time = tasks[next_task_id][2]
28+
else:
29+
# 工作
30+
working_task = heappop(min_heap)
31+
cur_time += working_task[0]
32+
res.append(working_task[1])
33+
34+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution(object):
2+
def sumBase(self, n, k):
3+
"""
4+
:type n: int
5+
:type k: int
6+
:rtype: int
7+
"""
8+
res = 0
9+
while n:
10+
res += n % k
11+
n //= k
12+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution(object):
2+
def longestBeautifulSubstring(self, word):
3+
"""
4+
:type word: str
5+
:rtype: int
6+
"""
7+
sequence = {"a":1, "e":2, "i":3, "o":4, "u":5}
8+
9+
last_vowel = None
10+
res = 0
11+
start = 0
12+
cur_set = set()
13+
for i, ch in enumerate(word):
14+
if not i or sequence[last_vowel] > sequence[ch]:
15+
start = i
16+
cur_set = set(ch)
17+
else:
18+
cur_set.add(ch)
19+
# print(cur_set)
20+
if ch == "u" and len(cur_set) == 5:
21+
res = max(res, i - start + 1)
22+
last_vowel = ch
23+
return res

0 commit comments

Comments
 (0)