Skip to content

Commit 010b5da

Browse files
authored
2022-08-08 update: added "Count Vowels Permutation" (#61)
1 parent 57d1532 commit 010b5da

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.smlnskgmail.jaman.leetcodejava.hard;
2+
3+
// https://leetcode.com/problems/count-vowels-permutation/
4+
public class CountVowelsPermutation {
5+
6+
private final int input;
7+
8+
public CountVowelsPermutation(int input) {
9+
this.input = input;
10+
}
11+
12+
public int solution() {
13+
long a = 1;
14+
long e = 1;
15+
long i = 1;
16+
long o = 1;
17+
long u = 1;
18+
long a2;
19+
long e2;
20+
long i2;
21+
long o2;
22+
long u2;
23+
long mod = (long) Math.pow(10, 9) + 7;
24+
for (int j = 2; j <= input; j++) {
25+
a2 = (e + i + u) % mod;
26+
e2 = (a + i) % mod;
27+
i2 = (e + o) % mod;
28+
o2 = i;
29+
u2 = (o + i) % mod;
30+
31+
a = a2;
32+
e = e2;
33+
i = i2;
34+
o = o2;
35+
u = u2;
36+
}
37+
return (int) ((a + e + i + o + u) % mod);
38+
}
39+
40+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.smlnskgmail.jaman.leetcodejava.hard;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class CountVowelsPermutationTest {
8+
9+
@Test
10+
public void defaultTest() {
11+
assertEquals(5, new CountVowelsPermutation(1).solution());
12+
}
13+
14+
}

0 commit comments

Comments
 (0)