leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit da47664efcdf452c35b6d4a7ad27ce932466ce91
parent c44453845ac5b4ca1cdabae40a93859ed66f7211
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat, 28 Oct 2023 16:33:12 +0000

Daily Problem

Diffstat:
AProblems/1220.cpp | 20++++++++++++++++++++
MREADME.md | 1+
2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/Problems/1220.cpp b/Problems/1220.cpp @@ -0,0 +1,20 @@ +class Solution { + static const int MOD = 1E9 + 7; + + public: + int countVowelPermutation(int n) { + long dp[5], pdp[5] = {1, 1, 1, 1, 1}; + for (int i = 1; i < n; i++) { + dp[0] = (pdp[1] + pdp[2] + pdp[4]) % MOD; + dp[1] = (pdp[0] + pdp[2]) % MOD; + dp[2] = (pdp[1] + pdp[3]) % MOD; + dp[3] = (pdp[2]) % MOD; + dp[4] = (pdp[2] + pdp[3]) % MOD; + swap(dp, pdp); + } + int res = 0; + for (int i = 0; i < 5; i++) + res = (res + pdp[i]) % MOD; + return res; + } +}; diff --git a/README.md b/README.md @@ -545,6 +545,7 @@ for solving problems. | 1209 | Medium | [Remove All Adjacent Duplicates in String II](Problems/1209.cpp) | | 1218 | Medium | [Longest Arithmetic Subsequence of Given Difference](Problems/1218.cpp) | | 1219 | Medium | [Path with Maximum Gold](Problems/1219.cpp) | +| 1220 | Hard | [Count Vowels Permutation](Problems/1220.cpp) | | 1222 | Medium | [Queens That Can Attack the King](Problems/1222.cpp) | | 1227 | Medium | [Airplane Seat Assignment Probability](Problems/1227.cpp) | | 1232 | Easy | [Check If It Is a Straight Line](Problems/1232.cpp) |