package leetcode;

/**
 * https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts/
 */
public class Problem1371 {
    public int findTheLongestSubstring(String s) {
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'a' || s.charAt(i) == 'e' || s.charAt(i) == 'i' ||
                s.charAt(i) == 'o' || s.charAt(i) == 'u') {
                // TODO
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        Problem1371 prob = new Problem1371();
        System.out.println(prob.findTheLongestSubstring("eleetminicoworoep")); // 13
        System.out.println(prob.findTheLongestSubstring("leetcodeisgreat")); // 5
        System.out.println(prob.findTheLongestSubstring("bcbcbc")); // 6
        System.out.println(prob.findTheLongestSubstring("eleetminicoworoepo")); // 18
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -237,24 +237,287 @@
 String s) %7B%0A
+        int answer = 0;%0A        char%5B%5D vowels = %7B'a', 'e', 'i', 'o', 'u'%7D;%0A        int%5B%5D pow = %7B1, 2, 4, 8, 16%7D;%0A        boolean%5B%5D odd = new boolean%5B5%5D;%0A        int code = 0;%0A        Map%3CInteger, Integer%3E encoded = new HashMap%3C%3E();%0A        encoded.put(code, -1);%0A
         for 
@@ -548,11 +548,11 @@
 (); 
-i
 ++
+i
 ) %7B%0A
@@ -567,161 +567,420 @@
     
-if (s.charAt(i) == 'a' %7C%7C s.charAt(i) == 'e' %7C%7C s.charAt(i) == 'i' %7C%7C%0A                s.charAt(i) == 'o' %7C%7C s.charAt(i) == 'u') %7B%0A                // TODO
+for (int j = 0; j %3C vowels.length; ++j) %7B%0A                if (s.charAt(i) == vowels%5Bj%5D) %7B%0A                    code += (odd%5Bj%5D ? -1 : 1) * pow%5Bj%5D;%0A                    odd%5Bj%5D = !odd%5Bj%5D;%0A                    break;%0A                %7D%0A            %7D%0A            if (encoded.containsKey(code)) %7B%0A                answer = Math.max(answer, i - encoded.get(code));%0A            %7D else %7B%0A                encoded.put(code, i);
 %0A   
@@ -1015,17 +1015,22 @@
  return 
-0
+answer
 ;%0A    %7D%0A
@@ -1117,24 +1117,26 @@
 blem1371();%0A
+//
         Syst
@@ -1208,16 +1208,316 @@
 ; // 13%0A
+//        System.out.println(prob.findTheLongestSubstring(%22xxx%22)); // 0%0A//        System.out.println(prob.findTheLongestSubstring(%22aabbbbee%22)); // 8%0A        System.out.println(prob.findTheLongestSubstring(%22aaabbbbee%22)); // 8%0A//        System.out.println(prob.findTheLongestSubstring(%22aaaa%22)); // 4%0A//
         
@@ -1590,16 +1590,18 @@
 ); // 5%0A
+//
         
@@ -1665,16 +1665,18 @@
 ); // 6%0A
+//
         

Update problem 1371