Skip to content

Instantly share code, notes, and snippets.

@sharmaabhinav
Created September 6, 2014 06:53
Show Gist options
  • Save sharmaabhinav/fb96becdec426a6a6898 to your computer and use it in GitHub Desktop.
Save sharmaabhinav/fb96becdec426a6a6898 to your computer and use it in GitHub Desktop.
public class HelloWorld{
public static void main(String []args){
int arr[] = new int[13];
fab(13, arr);
}
static int fab(int n, int arr[]){
if (n == 1 || n == 2 && arr[n - 1] == 0){
arr[n - 1] = 1;
System.out.println(1);
return 1;
}
if (arr[n - 1] != 0 ){
return arr[n - 1];
}else{
arr[n - 1] = fab(n - 2, arr) + fab(n - 1, arr);
System.out.println(arr[n - 1]);
return arr[n - 1];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment