Skip to content

Commit 414977f

Browse files
add 2063
1 parent f405d9a commit 414977f

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2063|[Vowels of All Substrings](https://leetcode.com/problems/vowels-of-all-substrings/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2063.java) ||Medium||
1112
|2062|[Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2062.java) ||Easy||
1213
|2058|[Find the Minimum and Maximum Number of Nodes Between Critical Points](https://leetcode.com/problems/find-the-minimum-and-maximum-number-of-nodes-between-critical-points/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2058.java) ||Medium||
1314
|2057|[Smallest Index With Equal Value](https://leetcode.com/problems/smallest-index-with-equal-value/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2057.java) ||Easy||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2063 {
4+
public static class Solution1 {
5+
/**
6+
* credit: https://leetcode.com/nevergiveup/
7+
*/
8+
public long countVowels(String word) {
9+
long ans = 0;
10+
for (int i = 0; i < word.length(); i++) {
11+
if (isVowel(word.charAt(i))) {
12+
long left = i;
13+
long right = word.length() - left - 1;
14+
ans += (left + 1) * (right + 1);
15+
}
16+
}
17+
return ans;
18+
}
19+
20+
private boolean isVowel(char ch) {
21+
return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._2063;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _2063Test {
10+
private static _2063.Solution1 solution1;
11+
private static String word;
12+
private static long expected;
13+
14+
@BeforeClass
15+
public static void setup() {
16+
solution1 = new _2063.Solution1();
17+
}
18+
19+
@Test
20+
public void test1() {
21+
word = "aba";
22+
expected = 6l;
23+
assertEquals(expected, solution1.countVowels(word));
24+
}
25+
26+
}

0 commit comments

Comments
 (0)