Skip to content

Commit 1f88143

Browse files
committed
Jun 07
1 parent 5625882 commit 1f88143

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution:
2+
def clearStars(self, s: str) -> str:
3+
n = len(s)
4+
indices = [[] for _ in range(26)] # indices of each char
5+
keep = [True] * n # flag to keep index in result
6+
7+
for i in range(n):
8+
if s[i] == '*':
9+
keep[i] = False # remove *
10+
# find first (smallest) char's latest index
11+
for j in range(26):
12+
if indices[j]:
13+
keep[indices[j].pop()] = False
14+
break
15+
else:
16+
# append index of current char
17+
indices[ord(s[i]) - ord('a')].append(i)
18+
19+
return ''.join(s[i] for i in range(n) if keep[i])
20+
21+
22+
def main():
23+
s = 'aaba*'
24+
assert Solution().clearStars(s) == 'aab'
25+
26+
s = 'abc'
27+
assert Solution().clearStars(s) == 'abc'
28+
29+
30+
if __name__ == '__main__':
31+
main()

2025-06-June-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
| June 04 | [3403. Find the Lexicographically Largest String From the Box I](https://leetcode.com/problems/find-the-lexicographically-largest-string-from-the-box-i/) | Medium | Solved |
1111
| June 05 | [1061. Lexicographically Smallest Equivalent String](https://leetcode.com/problems/lexicographically-smallest-equivalent-string) | Medium | Unsolved |
1212
| June 06 | [2434. Using a Robot to Print the Lexicographically Smallest String](https://leetcode.com/problems/using-a-robot-to-print-the-lexicographically-smallest-string/) | Medium | Unsolved |
13-
| June 07 | []() | | |
13+
| June 07 | [3170. Lexicographically Minimum String After Removing Stars](https://leetcode.com/problems/lexicographically-minimum-string-after-removing-stars/) | Medium | Solved |
1414
| June 08 | []() | | |
1515
| June 09 | []() | | |
1616
| June 10 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 0 | 0 | 0 |
43-
| Medium | 4 | 1 | 3 |
43+
| Medium | 5 | 2 | 3 |
4444
| Hard | 2 | 2 | 0 |

0 commit comments

Comments
 (0)