mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given a string <code>s</code> consisting <strong>only</strong> of letters <code>'a'</code> and <code>'b'</code>. In a single step you can remove one <strong>palindromic subsequence</strong> from <code>s</code>.</p>
 | 
						|
 | 
						|
<p>Return <em>the <strong>minimum</strong> number of steps to make the given string empty</em>.</p>
 | 
						|
 | 
						|
<p>A string is a <strong>subsequence</strong> 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 <strong>not</strong> necessarily need to be contiguous.</p>
 | 
						|
 | 
						|
<p>A string is called <strong>palindrome</strong> if is one that reads the same backward as well as forward.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "ababa"
 | 
						|
<strong>Output:</strong> 1
 | 
						|
<strong>Explanation:</strong> s is already a palindrome, so its entirety can be removed in a single step.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "abb"
 | 
						|
<strong>Output:</strong> 2
 | 
						|
<strong>Explanation:</strong> "<u>a</u>bb" -> "<u>bb</u>" -> "". 
 | 
						|
Remove palindromic subsequence "a" then "bb".
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 3:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "baabb"
 | 
						|
<strong>Output:</strong> 2
 | 
						|
<strong>Explanation:</strong> "<u>baa</u>b<u>b</u>" -> "<u>b</u>" -> "". 
 | 
						|
Remove palindromic subsequence "baab" then "b".
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>1 <= s.length <= 1000</code></li>
 | 
						|
	<li><code>s[i]</code> is either <code>'a'</code> or <code>'b'</code>.</li>
 | 
						|
</ul>
 |