1371. Find the Longest Substring Containing Vowels in Even Counts (Medium) - TengnanYao/daily_leetcode GitHub Wiki

class Solution(object):
    def findTheLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        vowels = {"a": 1, "e": 2, "i": 4, "o": 8, "u": 16}
        seen = {0: -1}
        result = cur = 0
        for i, c in enumerate(s):
            if c in vowels:
                cur ^= vowels[c]
            if cur not in seen:
                seen[cur] = i
            else:
                result = max(result, i - seen[cur])
        return result