Skip to content

Commit d7995c3

Browse files
authored
Create vowels-of-all-substrings.cpp
1 parent 27b086d commit d7995c3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

C++/vowels-of-all-substrings.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
long long countVowels(string word) {
7+
static const unordered_set<char> VOWELS = {'a', 'e', 'i', 'o', 'u'};
8+
9+
int64_t result = 0;
10+
for (int i = 0; i < size(word); ++i) {
11+
if (VOWELS.count(word[i])) {
12+
result += (i - 0 + 1)* ((size(word) - 1) - i + 1);
13+
}
14+
}
15+
return result;
16+
}
17+
};

0 commit comments

Comments
 (0)