题解 | #跳台阶#

跳台阶

https://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4

class Solution {
public:
    int dp[50]{0}; // initialize an array to store the number of ways to jump to each floor
    int jumpFloor(int number) {
        dp[1] = 1; // there is only one way to jump to the first floor
        dp[2] = 2; // there are two ways to jump to the second floor
        for(int i=3; i<=number;i++){
            dp[i] = dp[i-1] + dp[i-2]; // the number of ways to jump to the i-th floor is the sum of the number of ways to jump to the (i-1)th floor and the (i-2)th floor
        }
        return dp[number]; // return the number of ways to jump to the n-th floor
    }
};

全部评论

相关推荐

01-29 15:45
已编辑
华中科技大学 前端工程师
COLORSN:可以试一下,小厂看技术栈是不是很落后,如果太拉胯就别去,个人认为有实习氛围比你自己琢磨要高效不少,然后就是小厂其实也有可能会问的很难,这都比较难说,还是看自己项目含金量够不够,寒假还能不能推进学习再选择,毕竟去实习过年就10天假了
点赞 评论 收藏
分享
评论
2
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务