Skip to content

Commit

Permalink
[LeetCode] Add January 17.
Browse files Browse the repository at this point in the history
  • Loading branch information
pin3da authored Jan 17, 2021
1 parent b87c1d3 commit 3037205
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions solved/LeetCode/Challenges/2020/January/17.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution {
data class State(val n: Int, val last: Int)
val seen = mutableMapOf<State, Int>()

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
}
}

0 comments on commit 3037205

Please sign in to comment.