From 5a3dd6d16a82f911d33a1fb4eeaaab5d354c48d7 Mon Sep 17 00:00:00 2001 From: ceunnseo Date: Tue, 2 Sep 2025 10:29:28 +0900 Subject: [PATCH] Day07 --- .../Q3498.js" | 11 ++++++++++ .../Q1220.js" | 20 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 "leetcode2/1easy/\354\265\234\354\235\200\354\204\234/Q3498.js" create mode 100644 "leetcode2/3hard/\354\265\234\354\235\200\354\204\234/Q1220.js" diff --git "a/leetcode2/1easy/\354\265\234\354\235\200\354\204\234/Q3498.js" "b/leetcode2/1easy/\354\265\234\354\235\200\354\204\234/Q3498.js" new file mode 100644 index 00000000..02838fd9 --- /dev/null +++ "b/leetcode2/1easy/\354\265\234\354\235\200\354\204\234/Q3498.js" @@ -0,0 +1,11 @@ +/** + * @param {string} s + * @return {number} + */ +var reverseDegree = function (s) { + let res = 0; + for (let i = 0; i < s.length; i++) { + res += ("z".charCodeAt() - s[i].charCodeAt() + 1) * (i + 1); + } + return res; +}; diff --git "a/leetcode2/3hard/\354\265\234\354\235\200\354\204\234/Q1220.js" "b/leetcode2/3hard/\354\265\234\354\235\200\354\204\234/Q1220.js" new file mode 100644 index 00000000..1eb40d84 --- /dev/null +++ "b/leetcode2/3hard/\354\265\234\354\235\200\354\204\234/Q1220.js" @@ -0,0 +1,20 @@ +/** + * @param {number} n + * @return {number} + */ +var countVowelPermutation = function (n) { + const dp = Array.from({ length: n + 1 }, () => Array(5).fill(0)); + if (n === 1) return 5; + const MOD = 1000000007; + for (let i = 0; i < 5; i++) { + dp[1][i] = 1; + } + for (let i = 2; i < n + 1; i++) { + dp[i][0] = (dp[i - 1][1] + dp[i - 1][2] + dp[i - 1][4]) % MOD; //u,i,e 뒤 -> a로 끝남 + dp[i][1] = (dp[i - 1][0] + dp[i - 1][2]) % MOD; //a, i가 뒤 -> e로 끝남 + dp[i][2] = (dp[i - 1][1] + dp[i - 1][3]) % MOD; //e, o가 뒤 -> i로 끝남 + dp[i][3] = dp[i - 1][2] % MOD; //i가 뒤 -> o로 끝남 + dp[i][4] = (dp[i - 1][2] + dp[i - 1][3]) % MOD; //i, o가 뒤 -> u로 끝남 + } + return dp[n].reduce((cur, acc) => acc + cur, 0) % MOD; +};