Skip to content

Commit ccb7f36

Browse files
authored
Create maximum-number-of-vowels-in-a-substring-of-given-length.py
1 parent 465e6f8 commit ccb7f36

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def maxVowels(self, s, k):
6+
"""
7+
:type s: str
8+
:type k: int
9+
:rtype: int
10+
"""
11+
VOWELS = set("aeiou")
12+
result = curr = 0
13+
for i, c in enumerate(s):
14+
curr += c in VOWELS
15+
if i >= k:
16+
curr -= s[i-k] in VOWELS
17+
result = max(result, curr)
18+
return result

0 commit comments

Comments
 (0)