blob: 602d1b197d9535c999c0c5297211ccb5054edb33 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
package entries.kevindhir.aws;
import java.util.Arrays;
class Solution {
public int fib(int N) {
int[] storage = new int[9999];
Arrays.fill(storage, -1);
storage[0] = 0;
storage[1] = 1;
return fibMemoized(N, storage);
}
private int fibMemoized(int N, int[] storage){
if (storage[N] != -1) return storage[N];
int calculated = fibMemoized(N-1, storage) + fibMemoized(N-2, storage);
storage[N] = calculated;
return calculated;
}
}
|