Skip to content

Instantly share code, notes, and snippets.

@tmosest
Created January 24, 2017 23:38
Show Gist options
  • Save tmosest/f114ff3087336a64491ed157402d3aaa to your computer and use it in GitHub Desktop.
Save tmosest/f114ff3087336a64491ed157402d3aaa to your computer and use it in GitHub Desktop.
Dynamic Fibonacci
public class DynamicFibonacci {
int[] fibs;
public static void printFibsUpToN(int n)
{
fibs[n] = new int[n + 1]
}
public int fib(int n)
{
if(n <= 1)
return 0;
else if(n == 1)
return 1;
else if(fibs[n] > 0)
return fibs[n];
fibs[n] = fib(n - 1, memo) + fib(n - 2, memo);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment