forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_2063.java
More file actions
24 lines (22 loc) · 701 Bytes
/
_2063.java
File metadata and controls
24 lines (22 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.fishercoder.solutions;
public class _2063 {
public static class Solution1 {
/**
* credit: https://leetcode.com/nevergiveup/
*/
public long countVowels(String word) {
long ans = 0;
for (int i = 0; i < word.length(); i++) {
if (isVowel(word.charAt(i))) {
long left = i;
long right = word.length() - left - 1;
ans += (left + 1) * (right + 1);
}
}
return ans;
}
private boolean isVowel(char ch) {
return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}
}
}