Advertisement
nikunjsoni

70

Jun 12th, 2021
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int climbStairs(int n) {
  4.         if (n == 1)
  5.             return 1;
  6.         int first = 1;
  7.         int second = 2;
  8.         for(int i = 3; i <= n; i++) {
  9.             int third = first + second;
  10.             first = second;
  11.             second = third;
  12.         }
  13.         return second;
  14.     }
  15. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement