Created
October 13, 2020 05:28
-
-
Save aershov24/20d15e1789f23bd0ef8dc1e0a67c1c59 to your computer and use it in GitHub Desktop.
Markdium-14 Fibonacci Interview Questions (SOLVED) To Brush Before Coding Interview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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