Re: [闲聊] 每日LeetCode

楼主: Rushia (みけねこ的鼻屎)   2023-05-06 01:17:30
https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/description/
1456. Maximum Number of Vowels in a Substring of Given Length
给你一个包含小写字母的字串 s ,返回大小为 k 的子字串中,最大元音字母数量。
Example 1:
Input: s = "abciiidef", k = 3
Output: 3
Explanation: The substring "iii" contains 3 vowel letters.
Example 2:
Input: s = "aeiou", k = 2
Output: 2
Explanation: Any substring of length 2 contains 2 vowels.
思路:
1.大小为 n 的子字串要求最大的xx很明显是滑动窗口问题。
2.窗口每次加入一个字母,统计元音数量并更新最大元音数。
3.如果窗口大小超过 k 就移除最左边的字母并更新窗口内的元音数量。
Java Code:

Links booklink

Contact Us: admin [ a t ] ucptt.com