解题思路:
用一个数组存储前面所有字符中元音的个数
class Solution:
def maxVowels(self, s: str, k: int) -> int:
yuanyin=['a','e','i','o','u']
n=len(s)
max_val=0
if k==1:
for i in range(n):
if s[i] in yuanyin:
max_val=1
break
else:
dp=[0]
for i in range(n):
if s[i] in yuanyin:
dp.append(dp[-1]+1)
else:
dp.append(dp[-1])
dif=[dp[i+k]-dp[i] for i in range(n-k+1)]
max_val=max(dif)
return max_val