File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ 2390 . Removing Stars From a String(Medium)
2
+
3
+ You are given a string s, which contains stars * .
4
+
5
+ In one operation, you can:
6
+
7
+ Choose a star in s.
8
+ Remove the closest non-star character to its left, as well as remove the star itself.
9
+ Return the string after all stars have been removed.
10
+
11
+ Note:
12
+
13
+ The input will be generated such that the operation is always possible.
14
+ It can be shown that the resulting string will always be unique.
15
+
16
+
17
+ Example 1:
18
+
19
+ Input: s = "leet** cod* e"
20
+ Output: "lecoe"
21
+ Explanation: Performing the removals from left to right:
22
+ - The closest character to the 1st star is 't' in "leet** cod* e". s becomes "lee* cod* e".
23
+ - The closest character to the 2nd star is 'e' in "lee* cod* e". s becomes "lecod* e".
24
+ - The closest character to the 3rd star is 'd' in "lecod* e". s becomes "lecoe".
25
+ There are no more stars, so we return "lecoe".
26
+ Example 2:
27
+
28
+ Input: s = "erase***** "
29
+ Output: ""
30
+ Explanation: The entire string is removed, so we return an empty string.
31
+
32
+
33
+ Constraints:
34
+
35
+ 1 <= s.length <= 105
36
+ s consists of lowercase English letters and stars * .
37
+ The operation above can be performed on s.
You can’t perform that action at this time.
0 commit comments