You are viewing a single comment's thread. Return to all comments →
O(N) time and O(N) space dynamic solution.
def fibonacci(n,dp): if dp[n]!=-1: return dp[n] dp[n] = fibonacci(n-1,dp)+fibonacci(n-2,dp) return dp[n] n = int(input()) dp = [-1]*(n+1) dp[0] = 0 dp[1] = 1 print(fibonacci(n,dp))
Seems like cookies are disabled on this browser, please enable them to open this website
Recursion: Fibonacci Numbers
You are viewing a single comment's thread. Return to all comments →
O(N) time and O(N) space dynamic solution.