LeetCode 1456. Maximum Number of Vowels in a Substring of Given
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'
.
Example 1:
Input: s = "abciiidef", k = 3Output: 3Explanation: The substring "iii" contains 3 vowel letters.
Example 2:
Input: s = "aeiou", k = 2Output: 2Explanation: Any substring of length 2 contains 2 vowels.
Example 3:
Input: s = "leetcode", k = 3Output: 2Explanation: "lee", "eet" and "ode" contain 2 vowels.
Constraints:
1 <= s.length <= 105
s
consists of lowercase English letters.1 <= k <= s.length
1:写一个方法,判断是否是元音字母;
2:设置一个前缀和的数组;
3:依次判断连续K个数字之和,保存最大值;
4:返回最大值;
Runtime: 7 ms, faster than 99.58% of Java online submissions for Maximum Number of Vowels in a Substring of Given Length.
Memory Usage: 43.2 MB, less than 31.48% of Java online submissions for Maximum Number of Vowels in a Substring of Given Length.