How to make it more simple?


  • -2
    D

    int climbStairs(int n) {
    int f[2] = {1,2};
    int i = 1;
    if (n == 1)
    {
    i = 0;
    }
    n-=2;
    while(n-->0)
    {
    i = 1-i;
    f[i] = f[i] + f[1-i];
    }

    return f[i];
    

    }


Log in to reply
 

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