File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
main/java/com/smlnskgmail/jaman/leetcodejava/hard
test/java/com/smlnskgmail/jaman/leetcodejava/hard Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments