Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int climbStairs(int n) {
- if (n <= 2) {
- return n;
- }
- int nCurr = 1;
- int nNext = 2;
- int swap;
- for (int i = 3; i < n; i++) {
- swap = nNext;
- nNext = nNext + nCurr;
- nCurr = swap;
- }
- return nCurr + nNext;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement