package leetcode;

/**
 * https://leetcode.com/problems/number-of-substrings-containing-all-three-characters/
 */
public class Problem1358 {
    public int numberOfSubstrings(String s) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1358 prob = new Problem1358();
        System.out.println(prob.numberOfSubstrings("abcabc")); // 10
        System.out.println(prob.numberOfSubstrings("aaacb")); // 3
        System.out.println(prob.numberOfSubstrings("abc")); // 1
        System.out.println(prob.numberOfSubstrings("abcaaabcaa")); // 30
        System.out.println(prob.numberOfSubstrings("abcaa")); // 5
        System.out.println(prob.numberOfSubstrings("aaabc")); // 3
        System.out.println(prob.numberOfSubstrings("abcbb")); // 3
        System.out.println(prob.numberOfSubstrings("bbabc")); // 3
        System.out.println(prob.numberOfSubstrings("bbabcbbabcbb")); // 43
        System.out.println(prob.numberOfSubstrings("bbabcbb")); // 9
        System.out.println(prob.numberOfSubstrings("abcbbabc")); // 15
    }
}

@@ -192,15 +192,18 @@
     
-// TODO
+int a = 0;
 %0A   
@@ -211,22 +211,23 @@
     
-return
+int b =
  0;%0A    
 %7D%0A%0A 
@@ -226,858 +226,926 @@
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1358 prob = new Problem1358();%0A        System.out.println(prob.numberOfSubstrings(%22abcabc%22)); // 10%0A        System.out.println(prob.numberOfSubstrings(%22aaacb%22)); // 3%0A        System.out.println(prob.numberOfSubstrings(%22abc%22)); // 1%0A        System.out.println(prob.numberOfSubstrings(%22abcaaabcaa%22)); // 30%0A        System.out.println(prob.numberOfSubstrings(%22abcaa%22)); // 5%0A        System.out.println(prob.numberOfSubstrings(%22aaabc%22)); // 3%0A        System.out.println(prob.numberOfSubstrings(%22abcbb%22)); // 3%0A        System.out.println(prob.numberOfSubstrings(%22bbabc%22)); // 3%0A        System.out.println(prob.numberOfSubstrings(%22bbabcbbabcbb%22)); // 43%0A        System.out.println(prob.numberOfSubstrings(%22bbabcbb%22)); // 9%0A        System.out.println(prob.numberOfSubstrings(%22abcbbabc%22)); // 15
+int c = 0;%0A        int cur = 0;%0A        int prev = 0;%0A        int answer = 0;%0A        while (cur %3C s.length()) %7B%0A            if (s.charAt(cur) == 'a') %7B%0A                a++;%0A            %7D else if (s.charAt(cur) == 'b') %7B%0A                b++;%0A            %7D else %7B%0A                c++;%0A            %7D%0A            if (a %3E 0 && b %3E 0 && c %3E 0) %7B%0A                answer += s.length() - cur;%0A                while (a %3E 0 && b %3E 0 && c %3E 0) %7B%0A                    if (s.charAt(prev) == 'a') %7B%0A                        a--;%0A                    %7D else if (s.charAt(prev) == 'b') %7B%0A                        b--;%0A                    %7D else %7B%0A                        c--;%0A                    %7D%0A                    if (a %3E 0 && b %3E 0 && c %3E 0) %7B%0A                        answer += s.length() - cur;%0A                    %7D%0A                    prev++;%0A                %7D%0A            %7D%0A            cur++;%0A        %7D%0A        return answer;
 %0A   

Solve problem 1358