LeetCode 1456. Maximum Number of Vowels in a Substring of Given Length
2020-05-24 21:29:55
# leetcode
Problem
LeetCode 1456. Maximum Number of Vowels in a Substring of Given Length
1. 题目简述
给出一个字符串s和一个正整数k,返回以k长度的所有子字符串包含元音字母的最大值。例如:
Input: s = "abciiidef", k = 3
Output: 3
Explanation: The substring "iii" contains 3 vowel letters.
Constraints:
1 <= s.length <= 10^5
s consists of lowercase English letters.
1 <= k <= s.length
2. 算法思路
Sliding Window
这道题一眼就能看出来是sliding window,初始化以后每次移动一位,记录历史最大值。
3. 解法
- Sliding Window
使用Arrays.copyOfRange(int[] data, int start, int end)函数,写起来简洁,但是有点慢,而且耗空间大,因为要截取数组。
1 |
|