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