欢迎光临散文网 会员登陆 & 注册

LeetCode 1456. Maximum Number of Vowels in a Substring of Given

2023-02-12 08:12 作者:您是打尖儿还是住店呢  | 我要投稿

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.


LeetCode 1456. Maximum Number of Vowels in a Substring of Given 的评论 (共 条)

分享到微博请遵守国家法律