Last updated
Was this helpful?
Last updated
Was this helpful?
Given a string s
consisting only of letters 'a'
and 'b'
. In a single step you can remove one palindromic subsequence from s
.
Return the minimum number of steps to make the given string empty.
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.
A string is called palindrome if is one that reads the same backward as well as forward.
Example 1:
Example 2:
Example 3:
Example 4:
只由a和b组成的字符串s每步能移除掉一个回文序列,问把整个字符串清空至少需要多少步。分为三种情况:1. 空字符串,返回0;2. s本身已是回文,返回1;3. 其它,第一步清掉所有的a,第二步清掉b,最多需要两步。
https://leetcode.com/problems/remove-palindromic-subsequences/