10000 * Done with "2062. Count Vowel Substrings of a String". · garciparedes/leetcode@e67fb9f · GitHub
[go: up one dir, main page]

Skip to content

Commit e67fb9f

Browse files
committed
* Done with "2062. Count Vowel Substrings of a String".
1 parent be1d005 commit e67fb9f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
VOWELS = {"a", "e", "i", "o", "u"}
2+
3+
4+
class Solution:
5+
def countVowelSubstrings(self, word: str) -> int:
6+
ans = 0
7+
last_seen_consonant = -1
8+
last_seen_vowel = {v: -1 for v in VOWELS}
9+
for i in range(len(word)):
10+
c = word[i]
11+
if c in VOWELS:
12+
last_seen_vowel[c] = i
13+
ans += max(min(last_seen_vowel.values()) - last_seen_consonant, 0)
14+
else:
15+
last_seen_consonant = i
16+
return ans

0 commit comments

Comments
 (0)
0