1456.定长子串中元音的最大数目
方法:使用滑动窗口
class Solution {public int maxVowels(String s, int k) {int n = s.length();int sum = 0;for(int i = 0;i<k;i++){sum += isVowel(s.charAt(i));}int ans = sum;for(int i = k;i<n;i++){sum = sum + isVowel(s.charAt(i)) - isVowel(s.charAt(i-k));ans = Math.max(sum,ans);}return ans;}public int isVowel(char ch){return ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'?1:0;}
}