From 460aaa31a61696c01af80402754c66fb732f7a3b Mon Sep 17 00:00:00 2001 From: braxtonhall Date: Wed, 26 Oct 2022 10:24:40 -0700 Subject: Add Kevin Dhir --- entries/kevindhir/aws/Solution.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 entries/kevindhir/aws/Solution.java (limited to 'entries/kevindhir/aws/Solution.java') 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 -- cgit v1.2.3-70-g09d2