package leetcode;

/**
 * https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/
 */
public class Problem1003 {
    public boolean isValid(String S) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem1003 prob = new Problem1003();
        System.out.println(prob.isValid("aabcbc")); // true
        System.out.println(prob.isValid("abcabcababcc")); // true
        System.out.println(prob.isValid("abccba")); // false
        System.out.println(prob.isValid("cababc")); // false
    }
}

@@ -12,16 +12,41 @@
 tcode;%0A%0A
+import java.util.Stack;%0A%0A
 /**%0A * h
@@ -200,383 +200,528 @@
     
-// TODO%0A        return false;%0A
+Stack%3CCharacter%3E stack = new Stack%3C%3E();%0A        for (int i = 0; i %3C S.length(); i++) %7B%0A   
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1003 prob = new Problem1003();%0A        System.out.println(prob.isValid(%22aabcbc%22)); // true%0A        System.out.println(prob.isValid(%22abcabcababcc%22)); // true%0A        System.out.println(prob.isValid(%22abccba%22)); // false%0A        System.out.println(prob.isValid(%22cababc%22)); // false
+ char c = S.charAt(i);%0A            if (c == 'c') %7B%0A                if (stack.size() %3C 2) %7B%0A                    return false;%0A                %7D%0A                char b = stack.pop();%0A                char a = stack.pop();%0A                if (b != 'b' %7C%7C a != 'a') %7B%0A                    return false;%0A                %7D%0A            %7D else %7B%0A                stack.push(c);%0A            %7D%0A        %7D%0A        return stack.isEmpty();
 %0A   

Solve problem 1003