2696. Minimum String Length After Removing Substrings Easy

@problem@discussion
#String#Stack#Simulation



1/**
2 * [2696] Minimum String Length After Removing Substrings
3 *
4 * You are given a string s consisting only of uppercase English letters.
5 * You can apply some operations to this string where, in one operation, you can remove any occurrence of one of the substrings "AB" or "CD" from s.
6 * Return the minimum possible length of the resulting string that you can obtain.
7 * Note that the string concatenates after removing the substring and could produce new "AB" or "CD" substrings.
8 *  
9 * <strong class="example">Example 1:
10 * 
11 * Input: s = "ABFCACDB"
12 * Output: 2
13 * Explanation: We can do the following operations:
14 * - Remove the substring "<u>AB</u>FCACDB", so s = "FCACDB".
15 * - Remove the substring "FCA<u>CD</u>B", so s = "FCAB".
16 * - Remove the substring "FC<u>AB</u>", so s = "FC".
17 * So the resulting length of the string is 2.
18 * It can be shown that it is the minimum length that we can obtain.
19 * <strong class="example">Example 2:
20 * 
21 * Input: s = "ACBBD"
22 * Output: 5
23 * Explanation: We cannot do any operations on the string so the length remains the same.
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= s.length <= 100
29 * 	s consists only of uppercase English letters.
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/minimum-string-length-after-removing-substrings/
35// discuss: https://leetcode.com/problems/minimum-string-length-after-removing-substrings/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn min_length(s: String) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_2696() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.