You are viewing a single comment's thread. Return to all comments →
Kotlin O(n) time O(1) memory solution
fun fibonacciModified(t1: Int, t2: Int, n: Int): BigInteger { if (n == 1) return t1.toBigInteger() if (n == 2) return t2.toBigInteger() var tminus2 = t1.toBigInteger() var tminus1 = t2.toBigInteger() var ti = BigInteger.ZERO for (i in 3..n) { ti = tminus2 + tminus1*tminus1 tminus2 = tminus1 tminus1 = ti } return ti }
Seems like cookies are disabled on this browser, please enable them to open this website
Fibonacci Modified
You are viewing a single comment's thread. Return to all comments →
Kotlin O(n) time O(1) memory solution