Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.39 KB | None | 0 0
  1. /**
  2.  * This class should calculate Fibonacci numbers in linear time
  3.  * using recursion.
  4.  */
  5. public class LinearRecursive implements Fibonacci {
  6.  
  7.   @Override
  8.   public long fib(int n) {
  9.  
  10.  
  11.     return fibzz(n, 1, 0);
  12.     return -1; // Your code here.
  13.   }
  14.  
  15.  
  16.   int fibzz(int term, int val, int prev)
  17.   {
  18.     if(term == 0) return prev;
  19.     return fib(term - 1, val+prev, val);
  20.   }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement