13. Nth Fibonacci Number
My Approach
Explanation with Example
- Iteration 1: secondLast = 0 , last = 1 , curr = (0 + 1) = 1
- Iteration 2: secondLast = 1 , last = 1 , curr = (1 + 1) = 2
- Iteration 3: secondLast = 1 , last = 2 , curr = (1 + 2) = 3
- Iteration 4: secondLast = 2 , last = 3 , curr = (2 + 3) = 5Time and Auxiliary Space Complexity
Code (C++)
Contribution and Support
Last updated