Last active
May 27, 2018 18:49
-
-
Save thmain/2210823f41c8b236f4db to your computer and use it in GitHub Desktop.
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
public class Fibonacci{ | |
public static int fibTopDown(int n, int [] fib) { | |
if(n==0) return 0; | |
if(n==1) return 1; | |
if(fib[n]!=0){ | |
return fib[n]; | |
}else{ | |
fib[n] = fibTopDown(n-1, fib) + fibTopDown(n-2, fib); | |
return fib[n]; | |
} | |
} | |
public static void main(String[] args){ | |
int n = 10; | |
int [] fib = new int[n+1]; | |
System.out.println(fibTopDown(n, fib)); | |
} | |
} |
if(n==0) return 1; Should return 0 (zero)
Thanks , updated it
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is this supposed to be 0?