Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int fib(int n, ArrayList<Integer> arr){
- if(arr.size() > n){
- return arr.get(n);
- }
- if(n == 0){
- return 0;
- }
- if(n == 1){
- return 1;
- }
- int n2 = fib(n-2, arr);
- arr[n-2] = n2;
- int n1 = fib(n-1,arr);
- return n1+n2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement