1332. Remove Palindromic Subsequences Easy
1/**
2 * [1332] Remove Palindromic Subsequences
3 *
4 * You are given a string s consisting only of letters 'a' and 'b'. In a single step you can remove one palindromic subsequence from s.
5 * Return the minimum number of steps to make the given string empty.
6 * A string is a subsequence of a given string if it is generated by deleting some characters of a given string without changing its order. Note that a subsequence does not necessarily need to be contiguous.
7 * A string is called palindrome if is one that reads the same backward as well as forward.
8 *
9 * Example 1:
10 *
11 * Input: s = "ababa"
12 * Output: 1
13 * Explanation: s is already a palindrome, so its entirety can be removed in a single step.
14 *
15 * Example 2:
16 *
17 * Input: s = "abb"
18 * Output: 2
19 * Explanation: "<u>a</u>bb" -> "<u>bb</u>" -> "".
20 * Remove palindromic subsequence "a" then "bb".
21 *
22 * Example 3:
23 *
24 * Input: s = "baabb"
25 * Output: 2
26 * Explanation: "<u>baa</u>b<u>b</u>" -> "<u>b</u>" -> "".
27 * Remove palindromic subsequence "baab" then "b".
28 *
29 *
30 * Constraints:
31 *
32 * 1 <= s.length <= 1000
33 * s[i] is either 'a' or 'b'.
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/remove-palindromic-subsequences/
39// discuss: https://leetcode.com/problems/remove-palindromic-subsequences/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn remove_palindrome_sub(s: String) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_1332() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.