java.lang.Object
g2601_2700.s2696_minimum_string_length_after_removing_substrings.Solution

public class Solution extends Object
2696 - Minimum String Length After Removing Substrings.<p>Easy</p> <p>You are given a string <code>s</code> consisting only of <strong>uppercase</strong> English letters.</p> <p>You can apply some operations to this string where, in one operation, you can remove <strong>any</strong> occurrence of one of the substrings <code>&quot;AB&quot;</code> or <code>&quot;CD&quot;</code> from <code>s</code>.</p> <p>Return <em>the <strong>minimum</strong> possible length of the resulting string that you can obtain</em>.</p> <p><strong>Note</strong> that the string concatenates after removing the substring and could produce new <code>&quot;AB&quot;</code> or <code>&quot;CD&quot;</code> substrings.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;ABFCACDB&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> We can do the following operations:</p> <ul> <li>Remove the substring &ldquo;<ins>AB</ins>FCACDB&rdquo;, so s = &ldquo;FCACDB&rdquo;.</li> <li>Remove the substring &ldquo;FCA<ins>CD</ins>B&rdquo;, so s = &ldquo;FCAB&rdquo;.</li> <li>Remove the substring &ldquo;FC<ins>AB</ins>&rdquo;, so s = &ldquo;FC&rdquo;.</li> </ul> <p>So the resulting length of the string is 2.</p> <p>It can be shown that it is the minimum length that we can obtain.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;ACBBD&rdquo;</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> We cannot do any operations on the string so the length remains the same.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 100</code></li> <li><code>s</code> consists only of uppercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minLength

      public int minLength(String s)