当前位置:网站首页>NC68 跳台阶
NC68 跳台阶
2022-07-25 18:13:00 【syc596】
NC68 跳台阶
JZ69 跳台阶
// //递归
// public class Solution {
// public int jumpFloor(int target) {
// if(target==0){
// return 1;
// }
// if(target==1){
// return 1;
// }
// if(target==2){
// return 2;
// }
// return jumpFloor(target-1)+jumpFloor(target-2);
// }
// }
// //迭代1
// public class Solution {
// public int jumpFloor(int target) {
// if(target==0){
// return 1;
// }
// if(target==1){
// return 1;
// }
// if(target==2){
// return 2;
// }
// int first=1;
// int second=2;
// int third=0;
// while(target>2){
// third=first+second;
// first=second;
// second=third;
// target--;
// }
// return third;
// }
// }
// //迭代2
// public class Solution {
// public int jumpFloor(int target) {
// if(target==0){
// return 1;
// }
// if(target==1){
// return 1;
// }
// if(target==2){
// return 2;
// }
// int first=1;
// int second=2;
// int third=0;
// for(int i=3;i<=target;i++){
// third=first+second;
// first=second;
// second=third;
// }
// return third;
// }
// }
//11
//动规dp
public class Solution {
public int jumpFloor(int target) {
// if(target==0){
// return 1;
// }
// if(target==1){
// return 1;
// }
// if(target==2){
// return 2;
// }
int[] dp=new int[target+1];//target+1防止数组越界
dp[0]=1;
dp[1]=1;
for(int i=2;i<=target;i++){
dp[i]=dp[i-1]+dp[i-2];
}
return dp[target];
}
}边栏推荐
猜你喜欢

Tme2022 campus recruitment background development / operation development / business operation and maintenance / application development written examination (I) a little self analysis of programming q

Redis source code and design analysis -- 17. Redis event processing
![[MySQL]数据库中的索引为什么是用B+树来实现? 哈希表/红黑树/B树是否可行呢?](/img/1f/a2d50ec6bc97d52c1e7566a42e564b.png)
[MySQL]数据库中的索引为什么是用B+树来实现? 哈希表/红黑树/B树是否可行呢?

"Digital security" alert NFT's seven Scams

Cloud VR: the next step of virtual reality specialization

Oracle导入出错:IMP-00038: 无法转换为环境字符集句柄

Pan domain name configuration method

nodejs 简单例子程序之express

Auditing related notes

「数字安全」警惕 NFT的七大骗局
随机推荐
Which futures account is the best and safest
"Jargon" | what kind of experience is it to efficiently deliver games with Devops?
软件测试基础知识(思维导图)
C# Linq 去重&去重求和
Stm32f105rbt6 internal flash debugging
Use of C language cjson Library
Hit the test site directly: summary of common agile knowledge points in PMP examination
How to read a Book
What scenarios have rust, which is becoming more and more mature, applied?
对角化、A的幂
排序还需要了解的信息以及链表
更新|3DCAT实时云渲染 v2.1.2版本全新发布
Unittest framework application
CH582 BLE 5.0 使用 LE Coded 广播和连接
Update 3dcat real time cloud rendering V2.1.2 release
专访即构科技李凯:音视频的有趣、行业前沿一直吸引着我
Oracle导入出错:IMP-00038: 无法转换为环境字符集句柄
图的相关操作
Use of join function in MATLAB
文件基础知识