Class Solution
- 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.Medium
Given a string
s, determine if it is valid.A string
sis valid if, starting with an empty stringt = "", you can transformtintosafter performing the following operation any number of times:- Insert string
"abc"into any position int. More formally,tbecomestleft + “abc” + tright, wheret == tleft + tright. Note thattleftandtrightmay be empty.
Return
trueifsis a valid string, otherwise, returnfalse.Example 1:
Input: s = “aabcbc”
Output: true
Explanation: "" -> “abc” -> “aabcbc” Thus, “aabcbc” is valid.
Example 2:
Input: s = “abcabcababcc”
Output: true
Explanation: "" -> “abc” -> “abcabc” -> “abcabcabc” -> “abcabcababcc” Thus, “abcabcababcc” is valid.
Example 3:
Input: s = “abccba”
Output: false
Explanation: It is impossible to get “abccba” using the operation.
Constraints:
1 <= s.length <= 2 * 104sconsists of letters'a','b', and'c'
- Insert string
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
-
-
Method Detail
-
isValid
public boolean isValid(String s)
-
-