diff options
author | Lily Lin | 2022-10-26 23:30:06 +0000 |
---|---|---|
committer | Lily Lin | 2022-10-26 23:30:06 +0000 |
commit | af03b3cd051a8a8b1442147136156f271f07ac5c (patch) | |
tree | 6239bbd269f8c682fcd2bd1aecd29cc8b2edf6b5 /entries/kevindhir/aws/Solution.java | |
parent | 66fdac7a5ab7040a29fdd6a49cb0123db5ea916a (diff) | |
parent | 18d17f9fb578df5f20e689481ed06f44fcf4b80c (diff) |
Merge branch 'main' into lily
Diffstat (limited to 'entries/kevindhir/aws/Solution.java')
-rw-r--r-- | entries/kevindhir/aws/Solution.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/entries/kevindhir/aws/Solution.java b/entries/kevindhir/aws/Solution.java new file mode 100644 index 0000000..602d1b1 --- /dev/null +++ b/entries/kevindhir/aws/Solution.java @@ -0,0 +1,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; + } + +}
\ No newline at end of file |