My simple C++ solution


  • -1
    S

    class Solution {
    public:
    int climbStairs(int n) {
    int last2[] = {1,1};
    for(int i=0;i<n;i++){
    last2[i%2] = last2[0]+last2[1];
    }
    return last2[n%2];
    }
    };


  • 0
    Y

    the code is good except that it should be i <= n instead of i < n


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.