Open fockspaces opened 1 year ago
GPT imrprove:
class Solution:
def maxVowels(self, s: str, k: int) -> int:
vowels = set("aeiou")
cur_vowel = max_vowels = 0
for i in range(k):
if s[i] in vowels:
cur_vowel += 1
max_vowels = cur_vowel
for i in range(k, len(s)):
if s[i] in vowels:
cur_vowel += 1
if s[i - k] in vowels:
cur_vowel -= 1
max_vowels = max(max_vowels, cur_vowel)
return max_vowels
感覺有抓到 sliding window 的精髓