[LeetCode] 1137. N-th Tribonacci Number(Kotlin)

0

LeetCode

목록 보기
42/58
post-thumbnail
post-custom-banner

[LeetCode] 1137. N-th Tribonacci Number(Kotlin)

풀이

val memoization = MutableList<Int>(40){-1}

class Solution {
    fun tribonacci(n: Int): Int {
        if(n==0) return 0
        if(n==1) return 1
        if(n==2) return 1

        if(memoization[n] == -1) 
            memoization[n] = tribonacci(n-3) + tribonacci(n-2) + tribonacci(n-1)
        
        return memoization[n]
    }
}
profile
Be able to be vulnerable, in search of truth

0개의 댓글