A little bit confused about the problem description


  • 0
    U
    int climbStairs(int n){
    int dp[n + 1];
    fill_n(dp, n + 1, 0);
    dp[0] = 0;
    dp[1] = 1;
    dp[2] = 2;
    
    for(int i = 3; i <= n; ++i)
        dp[i] = dp[i - 1] + dp[i - 2];
        
    return dp[n];}
    

    Above is one of the desired solutions. The problem is simple if you consider "climb to the top" is an "exact reach" to top. However, at first glance, I think it's OK to climb "beyond" the top. I mean, for example, when n = 2, there are 3 ways of climbing: 1-1, 2 and 1-2. If the description wants to use "climbing stair" to visualize, my understanding might be more close to the reality.


Log in to reply
 

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