1456. Maximum Number of Vowels in a Substring of Given Length
Solution:
- similar to 643. Maximum Average Subarray I. almost the same. its a sliding window technique
class Solution:
def maxVowels(self, s: str, k: int) -> int:
def isVowel(c):
if c in set('aeiou'):
return True
else:
return False
ret = l = 0
for i in range(k):
if isVowel(s[i]):
l += 1
ret = l
for i in range(0, len(s) - k):
if isVowel(s[i]):
l -= 1
if isVowel(s[i + k]):
l += 1
if l > ret:
ret = l
return ret