Skip to content

Commit 5507f8d

Browse files
authored
Create find-the-longest-substring-containing-vowels-in-even-count.py
1 parent cabd7a8 commit 5507f8d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def findTheLongestSubstring(self, s):
6+
"""
7+
:type s: str
8+
:rtype: int
9+
"""
10+
VOWELS = "aeiou"
11+
result, mask, lookup = 0, 0, [None]*(2**len(VOWELS))
12+
lookup[0] = -1
13+
for i, c in enumerate(s):
14+
index = VOWELS.find(c)
15+
mask ^= (1 << index) if index >= 0 else 0
16+
if lookup[mask] is None:
17+
lookup[mask] = i
18+
result = max(result, i-lookup[mask])
19+
return result

0 commit comments

Comments
 (0)