MCPcopy Create free account
hub / github.com/careercup/ctci / fibonacci

Method fibonacci

java/Chapter 9/Introduction/FibonacciFB.java:6–18  ·  view source on GitHub ↗
(int i)

Source from the content-addressed store, hash-verified

4 public static int max = 100; // Make this as big as you want! (Though you'll exceed the bounds of a long around 46)
5 public static int[] fib = new int[max];
6 public static int fibonacci(int i) {
7 if (i == 0) {
8 return 0;
9 }
10 if (i == 1) {
11 return 1;
12 }
13 if (fib[i] != 0) {
14 return fib[i];
15 }
16 fib[i] = fibonacci(i - 1) + fibonacci(i - 2);
17 return fib[i];
18 }
19
20 /**
21 * @param args

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected