Leetcode 1473 Solution
This article provides solution to leetcode question 1473 (find-the-longest-substring-containing-vowels-in-even-counts)
Access this page by simply typing in "lcs 1473" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts
Solution
class Solution:
def findTheLongestSubstring(self, s: str) -> int:
best_pos_dict = {0: -1}
curr = 0
ans = 0
for i, ch in enumerate(s):
if ch in ['a', 'e', 'i', 'o', 'u']:
curr ^= 1 << (ord(ch) - ord('a'))
if curr not in best_pos_dict:
best_pos_dict[curr] = i
else:
ans = max(ans, i - best_pos_dict[curr])
return ans