From c525bff0cbb19db3debd4678a79da05f55950b93 Mon Sep 17 00:00:00 2001 From: Markus S Date: Mon, 30 Oct 2023 10:48:14 +0100 Subject: [PATCH] =?UTF-8?q?=C2=96Solution=20to=20today's=20problem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leetcode/lc1/lc1200/Problem1220.java | 40 +++++++++++++++++++ .../leetcode/lc1/lc1200/Problem1220Test.java | 22 ++++++++++ 2 files changed, 62 insertions(+) create mode 100755 src/main/java/com/github/spannm/leetcode/lc1/lc1200/Problem1220.java create mode 100755 src/test/java/com/github/spannm/leetcode/lc1/lc1200/Problem1220Test.java diff --git a/src/main/java/com/github/spannm/leetcode/lc1/lc1200/Problem1220.java b/src/main/java/com/github/spannm/leetcode/lc1/lc1200/Problem1220.java new file mode 100755 index 00000000..495b2906 --- /dev/null +++ b/src/main/java/com/github/spannm/leetcode/lc1/lc1200/Problem1220.java @@ -0,0 +1,40 @@ +package com.github.spannm.leetcode.lc1.lc1200; + +import com.github.spannm.leetcode.LeetcodeProblem; + +/** + * 1220. Count Vowels Permutation. + */ +public class Problem1220 extends LeetcodeProblem { + + public int countVowelPermutation(int _n) { + int mod = 1000_000_007; + long ca = 1; + long ce = 1; + long ci = 1; + long co = 1; + long cu = 1; + long a; + long e; + long i; + long o; + long u; + + while (--_n > 0) { + a = (ce + ci + cu) % mod; + e = (ca + ci) % mod; + i = (ce + co) % mod; + o = ci; + u = (ci + co) % mod; + + ca = a; + ce = e; + ci = i; + co = o; + cu = u; + } + + return (int) ((ca + ce + ci + co + cu) % mod); + } + +} diff --git a/src/test/java/com/github/spannm/leetcode/lc1/lc1200/Problem1220Test.java b/src/test/java/com/github/spannm/leetcode/lc1/lc1200/Problem1220Test.java new file mode 100755 index 00000000..d9c9da44 --- /dev/null +++ b/src/test/java/com/github/spannm/leetcode/lc1/lc1200/Problem1220Test.java @@ -0,0 +1,22 @@ +package com.github.spannm.leetcode.lc1.lc1200; + +import com.github.spannm.leetcode.LeetcodeBaseTest; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class Problem1220Test extends LeetcodeBaseTest { + + @ParameterizedTest(name = "[{index}] {0} --> {1}") + @CsvSource(delimiter = ';', value = { + "1; 5", + "2; 10", + "5; 68" + }) + void test( + int _n, + int _expectedResult) { + + assertEquals(_expectedResult, new Problem1220().countVowelPermutation(_n)); + } + +}