java.lang.Object
g1001_1100.s1003_check_if_word_is_valid_after_substitutions.Solution

public class Solution extends Object
1003 - Check If Word Is Valid After Substitutions.<p>Medium</p> <p>Given a string <code>s</code>, determine if it is <strong>valid</strong>.</p> <p>A string <code>s</code> is <strong>valid</strong> if, starting with an empty string <code>t = &quot;&quot;</code>, you can <strong>transform</strong> <code>t</code> <strong>into</strong> <code>s</code> after performing the following operation <strong>any number of times</strong>:</p> <ul> <li>Insert string <code>&quot;abc&quot;</code> into any position in <code>t</code>. More formally, <code>t</code> becomes <code>t<sub>left</sub> + &ldquo;abc&rdquo; + 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 <strong>empty</strong>.</li> </ul> <p>Return <code>true</code> <em>if</em> <code>s</code> <em>is a <strong>valid</strong> string, otherwise, return</em> <code>false</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;aabcbc&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> &quot;&quot; -> &ldquo;abc&rdquo; -> &ldquo;aabcbc&rdquo; Thus, &ldquo;aabcbc&rdquo; is valid.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;abcabcababcc&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> &quot;&quot; -> &ldquo;abc&rdquo; -> &ldquo;abcabc&rdquo; -> &ldquo;abcabcabc&rdquo; -> &ldquo;abcabcababcc&rdquo; Thus, &ldquo;abcabcababcc&rdquo; is valid.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;abccba&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> It is impossible to get &ldquo;abccba&rdquo; using the operation.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 2 * 10<sup>4</sup></code></li> <li><code>s</code> consists of letters <code>'a'</code>, <code>'b'</code>, and <code>'c'</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isValid

      public boolean isValid(String s)