Created
October 6, 2024 00:46
-
-
Save igavrysh/e11f44686bd87b14f59405517c4078c1 to your computer and use it in GitHub Desktop.
Leetcode2062 solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://leetcode.com/problems/count-vowel-substrings-of-a-string/ | |
// https://youtu.be/hGH_Z4_jMBI | |
/// | |
class Solution { | |
public int countVowelSubstrings(String word) { | |
int n = word.length(); | |
int[] fq = new int[26]; | |
int k = 0; int l = 0; | |
int res = 0; | |
for (int r = 0; r < n; r++) { | |
char ch = word.charAt(r); | |
if (ch == 'a' || ch == 'o' || ch == 'e' || ch == 'i' || ch == 'u') { | |
fq[ch-'a']++; | |
if (fq[(int)'a'-'a']>0 && fq[(int)'o'-'a']>0 | |
&& fq[(int)'e'-'a']>0 && fq[(int)'i'-'a']>0 | |
&& fq[(int)'u'-'a']>0 | |
) { | |
while (fq[word.charAt(k)-'a']>1) { | |
fq[word.charAt(k)-'a']--; | |
k++; | |
} | |
res += (k-l+1); | |
} | |
} else { | |
fq = new int[26]; | |
k = r+1; | |
l = r+1; | |
} | |
} | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment