2390. Removing Stars From a String Medium

@problem@discussion
#String#Stack#Simulation



1/**
2 * [2390] Removing Stars From a String
3 *
4 * You are given a string s, which contains stars *.
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 * 
10 * Return the string after all stars have been removed.
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 1^st star is 't' in "lee<u>t</u>**cod*e". s becomes "lee*cod*e".
23 * - The closest character to the 2^nd star is 'e' in "le<u>e</u>*cod*e". s becomes "lecod*e".
24 * - The closest character to the 3^rd star is 'd' in "leco<u>d</u>*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 <= 10^5
36 * 	s consists of lowercase English letters and stars *.
37 * 	The operation above can be performed on s.
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/removing-stars-from-a-string/
43// discuss: https://leetcode.com/problems/removing-stars-from-a-string/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn remove_stars(s: String) -> String {
49        String::new()
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_2390() {
61    }
62}
63


Back
© 2025 bowen.ge All Rights Reserved.