From 3037205bba2852e7a824f7679b439aab95289dbc Mon Sep 17 00:00:00 2001 From: Manuel Pineda Date: Sun, 17 Jan 2021 13:01:21 +0100 Subject: [PATCH] [LeetCode] Add January 17. --- solved/LeetCode/Challenges/2020/January/17.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 solved/LeetCode/Challenges/2020/January/17.kt diff --git a/solved/LeetCode/Challenges/2020/January/17.kt b/solved/LeetCode/Challenges/2020/January/17.kt new file mode 100644 index 00000000..d4361f5f --- /dev/null +++ b/solved/LeetCode/Challenges/2020/January/17.kt @@ -0,0 +1,25 @@ +class Solution { + data class State(val n: Int, val last: Int) + val seen = mutableMapOf() + + fun countVowelStrings(n: Int): Int { + return count(State(n, 0)) + } + + private fun count(s: State) : Int { + if (s.n == 0) { + return 1 + } + + if (seen.contains(s)) { + return seen[s]!! + } + + var ans = 0 + for (next in s.last..4) { + ans += count(State(s.n-1, next)) + } + seen[s] = ans + return ans + } +}