3039. Apply Operations to Make String Empty Medium
1/**
2 * [3039] Apply Operations to Make String Empty
3 *
4 * You are given a string s.
5 * Consider performing the following operation until s becomes empty:
6 *
7 * For every alphabet character from 'a' to 'z', remove the first occurrence of that character in s (if it exists).
8 *
9 * For example, let initially s = "aabcbbca". We do the following operations:
10 *
11 * Remove the underlined characters s = "<u>a</u>a<u>bc</u>bbca". The resulting string is s = "abbca".
12 * Remove the underlined characters s = "<u>ab</u>b<u>c</u>a". The resulting string is s = "ba".
13 * Remove the underlined characters s = "<u>ba</u>". The resulting string is s = "".
14 *
15 * Return the value of the string s right before applying the last operation. In the example above, answer is "ba".
16 *
17 * <strong class="example">Example 1:
18 *
19 * Input: s = "aabcbbca"
20 * Output: "ba"
21 * Explanation: Explained in the statement.
22 *
23 * <strong class="example">Example 2:
24 *
25 * Input: s = "abcd"
26 * Output: "abcd"
27 * Explanation: We do the following operation:
28 * - Remove the underlined characters s = "<u>abcd</u>". The resulting string is s = "".
29 * The string just before the last operation is "abcd".
30 *
31 *
32 * Constraints:
33 *
34 * 1 <= s.length <= 5 * 10^5
35 * s consists only of lowercase English letters.
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/apply-operations-to-make-string-empty/
41// discuss: https://leetcode.com/problems/apply-operations-to-make-string-empty/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn last_non_empty_string(s: String) -> String {
47 String::new()
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_3039() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.