Skip to content

Commit bdef290

Browse files
authored
Merge pull request #2997 from Anukriti167/patch-14
Create 1456-maximum-number-of-vowels-in-a-substring-of-given-length.java
2 parents 2ae20b0 + a373bd8 commit bdef290

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int maxVowels(String s, int k) {
3+
Set<Character> set = new HashSet<>();
4+
Collections.addAll(set, 'a', 'e', 'i', 'o', 'u');
5+
6+
int l=0, cnt=0, res=0;
7+
8+
for(int r=0; r<s.length(); r++){
9+
cnt += set.contains(s.charAt(r))?1:0;
10+
if(r-l+1 > k){
11+
cnt -= set.contains(s.charAt(l))?1:0;
12+
l++;
13+
}
14+
res = Math.max(res, cnt);
15+
}
16+
return res;
17+
}
18+
}

0 commit comments

Comments
 (0)