aboutsummaryrefslogtreecommitdiff
path: root/find_longest_substr_vowel.py
blob: a9974abc917f78e62548b0d6580dd383040d4d7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 1371. Find the Longest Substring Containing Vowels in Even Counts

"""
given the string 's', return the size of the longest substring containing
each value an even number of times. that is 'a, e, i, o, u' must appear an
even number of times.
"""


class Solution(object):
    def findTheLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        seen = {0: -1}
        ans, curr = 0, 0
        for i, j in enumerate(s):
            curr ^= 1 << ("aeiou".find(j) + 1) >> 1
            seen.setdefault(curr, i)
            ans = max(ans, i - seen[curr])
        return ans


if __name__ == "__main__":
    obj = Solution()
    print(obj.findTheLongestSubstring("eleetminicoworoep"))
    print(obj.findTheLongestSubstring("leetcodeisgreat"))
    print(obj.findTheLongestSubstring("bcbcbc"))