当前位置:网站首页>leetcode 剑指 Offer 10- II. 青蛙跳台阶问题
leetcode 剑指 Offer 10- II. 青蛙跳台阶问题
2022-07-30 08:52:00 【kt1776133839】
题目描述:
一只青蛙一次可以跳上1级台阶,也可以跳上2级台阶。求该青蛙跳上一个 n 级的台阶总共有多少种跳法。
答案需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1。
样例:
示例 1:
输入:n = 2
输出:2
示例 2:
输入:n = 7
输出:21
示例 3:
输入:n = 0
输出:1
提示:
0 <= n <= 100
class Solution {
public int numWays(int n) {
int a = 1, b = 1, sum;
for(int i = 0; i < n; i++){
sum = (a + b) % 1000000007;
a = b;
b = sum;
}
return a;
}
}
边栏推荐
猜你喜欢
随机推荐
电源完整性的去耦和层间耦合电容
Leetcode - 990: equations of satisfiability
2022杭电多校第一场
pnpm简介
分布式系统大势所趋,银行运维如何与时俱进?
[Fun BLDC series with zero basics] Taking GD32F30x as an example, the timer related functions are explained in detail
Unable to locate the program input point ucrtbase.abort on the dynamic link library api-ms-win-crt-runtime-|1-1-0.dll
Two solutions for Excel xlsx file not supported
How to run dist file on local computer
els 方块向左移动
用示波器揭示以太网传输机制
一个低级错误导致的诡异现象——走近科学能拍三集,(C语言)最简单的数组元素读取,不正确!?
怎么在本地电脑上运行dist文件
HCIP - MPLS VPN experiment
Only after such a stage of development can digital retail have a new evolution
公共Jar包的版本管理
初识Apifox——如何使用Apifox做一个简单的接口测试
02-课程发布
获取显示器数据
BaseQuickAdapter方法getBindingAdapterPosition









