Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    1003 - Check If Word Is Valid After Substitutions.

    Medium

    Given a string s, determine if it is valid.

    A string s is valid if, starting with an empty string t = "", you can transform t into s after performing the following operation any number of times:

    • Insert string "abc" into any position in t. More formally, t becomes <code>t<sub>left</sub> + "abc" + t<sub>right</sub></code>, where <code>t == t<sub>left</sub> + t<sub>right</sub></code>. Note that <code>t<sub>left</sub></code> and <code>t<sub>right</sub></code> may be empty.

    Return true if s is a valid string, otherwise, return false.

    Example 1:

    Input: s = "aabcbc"

    Output: true

    Explanation: "" -> "<ins>abc</ins>" -> "a<ins>abc</ins>bc" Thus, "aabcbc" is valid.

    Example 2:

    Input: s = "abcabcababcc"

    Output: true

    Explanation: "" -> "<ins>abc</ins>" -> "abc<ins>abc</ins>" -> "abcabc<ins>abc</ins>" -> "abcabcab<ins>abc</ins>c" Thus, "abcabcababcc" is valid.

    Example 3:

    Input: s = "abccba"

    Output: false

    Explanation: It is impossible to get "abccba" using the operation.

    Constraints:

    • <code>1 <= s.length <= 2 * 10<sup>4</sup></code>

    • s consists of letters 'a', 'b', and 'c'

    • 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 Boolean isValid(String s)
      • Methods inherited from class java.lang.Object

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