java.lang.Object
g1301_1400.s1332_remove_palindromic_subsequences.Solution

public class Solution extends Object
1332 - Remove Palindromic Subsequences.<p>Easy</p> <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><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;ababa&rdquo;</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> s is already a palindrome, so its entirety can be removed in a single step.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;abb&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> &ldquo;abb&rdquo; -> &ldquo;bb&rdquo; -> &quot;&quot;. Remove palindromic subsequence &ldquo;a&rdquo; then &ldquo;bb&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;baabb&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> &ldquo;baabb&rdquo; -> &ldquo;b&rdquo; -> &quot;&quot;. Remove palindromic subsequence &ldquo;baab&rdquo; then &ldquo;b&rdquo;.</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>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • removePalindromeSub

      public int removePalindromeSub(String s)