1003. Check If Word Is Valid After Substitutions Medium

@problem@discussion
#String#Stack



1/**
2 * [1003] Check If Word Is Valid After Substitutions
3 *
4 * Given a string s, determine if it is valid.
5 * 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:
6 * 
7 * 	Insert string "abc" into any position in t. More formally, t becomes tleft + "abc" + tright, where t == tleft + tright. Note that tleft and tright may be empty.
8 * 
9 * Return true if s is a valid string, otherwise, return false.
10 *  
11 * Example 1:
12 * 
13 * Input: s = "aabcbc"
14 * Output: true
15 * Explanation:
16 * "" -> "<u>abc</u>" -> "a<u>abc</u>bc"
17 * Thus, "aabcbc" is valid.
18 * Example 2:
19 * 
20 * Input: s = "abcabcababcc"
21 * Output: true
22 * Explanation:
23 * "" -> "<u>abc</u>" -> "abc<u>abc</u>" -> "abcabc<u>abc</u>" -> "abcabcab<u>abc</u>c"
24 * Thus, "abcabcababcc" is valid.
25 * 
26 * Example 3:
27 * 
28 * Input: s = "abccba"
29 * Output: false
30 * Explanation: It is impossible to get "abccba" using the operation.
31 * 
32 *  
33 * Constraints:
34 * 
35 * 	1 <= s.length <= 2 * 10^4
36 * 	s consists of letters 'a', 'b', and 'c'
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/
42// discuss: https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn is_valid(s: String) -> bool {
48        false
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_1003() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.