Skip to content

Instantly share code, notes, and snippets.

@aershov24
Created October 13, 2020 05:28
Show Gist options
  • Select an option

  • Save aershov24/20d15e1789f23bd0ef8dc1e0a67c1c59 to your computer and use it in GitHub Desktop.

Select an option

Save aershov24/20d15e1789f23bd0ef8dc1e0a67c1c59 to your computer and use it in GitHub Desktop.
Markdium-14 Fibonacci Interview Questions (SOLVED) To Brush Before Coding Interview
static int fibMemo[];
public static int fibByRecMemo(int num) {
if (num == 0) {
fibMemo[0] = 0;
return 0;
}
if (num == 1 || num == 2) {
fibMemo[num] = 1;
return 1;
}
if (fibMemo[num] == 0) {
fibMemo[num] = fibByRecMemo(num - 1) + fibByRecMemo(num - 2);
return fibMemo[num];
} else {
return fibMemo[num];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment