首页 > 试题广场 >

上台阶

[编程题]上台阶
  • 热度指数:30005 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解

有一楼梯共m级,刚开始时你在第一级,若每次只能跨上一级或者二级,要走上m级,共有多少走法?注:规定从一级到一级有0种走法。

给定一个正整数int n,请返回一个数,代表上楼的方式数。保证n小于等于100。为了防止溢出,请返回结果Mod 1000000007的值。

测试样例:
3
返回:2
头像 bao_hu_yuan_zhang
发表于 2024-02-17 10:47:55
class GoUpstairs { public: int countWays(int n) { if(n==1) { return 0; } if(n==2) { 展开全文
头像 17c89
发表于 2024-03-29 13:44:11
import java.util.*; /** * JD4 上台阶 * @author d3y1 */ public class GoUpstairs { private static final int MOD = 1000000007; /** * 动态规划 展开全文
头像 呀呀呀想巴摁噢来
发表于 2022-08-15 17:59:01
class GoUpstairs:     def countWays(self, n):         res = [0,1]         while len(res) <= n: &n 展开全文