Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fibonacci 2
import java.util.*; import java.lang.*; /*Taken from http://introcs.cs.princeton.edu/java/23recursion/TopDownFibonacci.java.html 20170504*/ class Rextester { private static long[] f = new long[92]; public static long fibonacci(int n) { if (n == 0) return 0; if (n == 1) return 1; // return cached value (if previously computed) if (f[n] > 0) return f[n]; // compute and cache value f[n] = fibonacci(n-1) + fibonacci(n-2); return f[n]; } public static void main(String[] args) { int n = 10; for (int i = 0; i <= n; i++) System.out.print(" i" + i + ": " + fibonacci(i)); } }
run
|
edit
|
history
|
help
0
binary square root
Alphabets
different ways to add parenthesis leetcode #241
4.b
ArrayOperation
pk3
nested
Minimum Vertices to Traverse Directed Graph
Path finding given 2D array
reservation vehicules