Class Solution
java.lang.Object
g1001_1100.s1003_check_if_word_is_valid_after_substitutions.Solution
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 = ""</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>"abc"</code> into any position in <code>t</code>. More formally, <code>t</code> 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 <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 = “aabcbc”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> "" -> “abc” -> “aabcbc” Thus, “aabcbc” is valid.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “abcabcababcc”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> "" -> “abc” -> “abcabc” -> “abcabcabc” -> “abcabcababcc” Thus, “abcabcababcc” is valid.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “abccba”</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> It is impossible to get “abccba” 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 Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
isValid
-