Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int climbStairs(int n) {
  6. if (n==0) return 0;
  7. int sum=1, prev=1; //we actually start from 3rd fibonacci number
  8. for (int i=1; i<n; ++i) {
  9. int next = sum + prev;
  10. prev = sum;
  11. sum = next;
  12. }
  13. return sum;
  14. }
  15.  
  16. int main() {
  17. cout << climbStairs(44) << "\n";
  18. return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement