Advertisement
vaibhav1906

Fibonacci

Dec 18th, 2021
1,451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.28 KB | None | 0 0
  1. class Solution {
  2. public:
  3.    
  4.     int f(int n){
  5.        
  6.         if(n==0) return 0;
  7.         if(n==1) return 1;
  8.        
  9.         return f(n-1) + f(n-2);
  10.        
  11.     }
  12.    
  13.     int fib(int n) {
  14.        
  15.         int ans = f(n);
  16.        
  17.         return ans;
  18.        
  19.     }
  20. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement