Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    2696 - Minimum String Length After Removing Substrings.

    Easy

    You are given a string s consisting only of uppercase English letters.

    You can apply some operations to this string where, in one operation, you can remove any occurrence of one of the substrings "AB" or "CD" from s.

    Return the minimum possible length of the resulting string that you can obtain.

    Note that the string concatenates after removing the substring and could produce new "AB" or "CD" substrings.

    Example 1:

    Input: s = "ABFCACDB"

    Output: 2

    Explanation: We can do the following operations:

    • Remove the substring "<ins>AB</ins>FCACDB", so s = "FCACDB".

    • Remove the substring "FCA<ins>CD</ins>B", so s = "FCAB".

    • Remove the substring "FC<ins>AB</ins>", so s = "FC".

    So the resulting length of the string is 2.

    It can be shown that it is the minimum length that we can obtain.

    Example 2:

    Input: s = "ACBBD"

    Output: 5

    Explanation: We cannot do any operations on the string so the length remains the same.

    Constraints:

    • 1 &lt;= s.length &lt;= 100

    • s consists only of uppercase English letters.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer minLength(String s)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait