This commit is contained in:
parent
7763227f07
commit
cd0bb8d030
1 changed files with 17 additions and 0 deletions
|
|
@ -0,0 +1,17 @@
|
||||||
|
# https://leetcode.com/problems/lexicographically-minimum-string-after-removing-stars
|
||||||
|
|
||||||
|
import heapq
|
||||||
|
|
||||||
|
class Solution:
|
||||||
|
def clearStars(self, s: str) -> str:
|
||||||
|
result = list(s)
|
||||||
|
h = []
|
||||||
|
for i in range(len(s)):
|
||||||
|
if s[i] == '*':
|
||||||
|
(_, _, origin) = heapq.heappop(h)
|
||||||
|
result[origin] = ''
|
||||||
|
result[i] = ''
|
||||||
|
else:
|
||||||
|
heapq.heappush(h, (s[i], -i, i))
|
||||||
|
return ''.join(result)
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue