leetcode

Leetcode submissions
git clone git://git.laack.co/leetcode.git
Log | Files | Refs | README

fibonacci-number.cpp (317B)


      1 //Find the nth value in the fibonacci number sequence.
      2 //I did this recursively with a time complexity of O(2^n).
      3 //Time: 11ms Beats: 47.1%
      4 //Memory: 5.9MB Beats: 94.32%
      5 class Solution {
      6 public:
      7     int fib(int n) {
      8         if(n <= 1){
      9             return n;
     10         }
     11         return fib(n - 1) + fib(n - 2);
     12     }
     13 };