1456. Maximum Number of Vowels in a Substring of Given Length
Question
Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k.
Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'.
Solution
使用count记录元音数量,max记录元音的最大值。
遍历字符串,如果当前字符属于元音,则count++。
同时,如果移动出的字符是元音,则count–。
每次遍历结束更新max值。
最后返回max。
Code
1 | class Solution { |
1456. Maximum Number of Vowels in a Substring of Given Length
https://xuanhe95.github.io/2023/05/05/1456-Maximum-Number-of-Vowels-in-a-Substring-of-Given-Length/
