class Solution:
def maxVowels(self, s: str, k: int) -> int:
q = collections.deque(s[:k])
vowel = ['a', 'e', 'i', 'o', 'u']
count = 0
max_count = 0
for v in vowel:
count += s[:k].count(v)
max_count = max(max_count, count)
i = k
while i < len(s):
if q.popleft() in vowel:
count -= 1
x = s[i]
q.append(x)
if x in vowel:
count += 1
max_count = max(max_count, count)
if count == k:
return k
i = i + 1
return max_count
'CS > 알고리즘' 카테고리의 다른 글
[Leetcode] 34. Find First and Last Position of Element in Sorted Array (0) | 2023.05.09 |
---|---|
[Leetcode] 1498. Number of Subsequences That Satisfy the Given Sum Condition (1) | 2023.05.06 |
[Leetcode] 649. Dota2 Senate (0) | 2023.05.05 |
[Leetcode] 986. Interval List Intersections (0) | 2023.05.05 |
[Leetcode] 844. Backspace String Compare (0) | 2023.05.05 |