C++ 0ms


  • 1
    L
    int climbStairs(int n) {
        // if(n == 0 || n == 1)
        //     return 1;
        // else
        //     return climbStairs(n-1) + climbStairs(n-2);
        int a[1000];
        a[0] = 1;
        a[1] = 1;
        for(int i = 2; i <= n; i++)
        {
            a[i] = a[i-1] + a[i-2]
        }
        return a[n];
    }

Log in to reply
 

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