kuza2010

Climb stairs solution

Nov 27th, 2021
749
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2.     public int climbStairs(int n) {
  3.         if (n <= 2) {
  4.             return n;
  5.         }
  6.  
  7.         int nCurr = 1;
  8.         int nNext = 2;
  9.         int swap;
  10.  
  11.         for (int i = 3; i < n; i++) {
  12.             swap = nNext;
  13.             nNext = nNext + nCurr;
  14.             nCurr = swap;
  15.         }
  16.  
  17.         return nCurr + nNext;
  18.     }
  19. }
RAW Paste Data