当前位置:网站首页>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];
}
}边栏推荐
- Optimistic lock pessimistic lock applicable scenario
- 如何选择数字孪生可视化平台
- Linux启动mysql报错
- OV7725 yuv 640*[email protected] 配置文件
- 越来越成熟的Rust,都应用了哪些场景呢?
- "Digital security" alert NFT's seven Scams
- UFT (QTP) - summary points and automated test framework
- Mock服务moco系列(三)- 重定向、正则表达式、延迟、模板、事件、分模块设计
- 使用sqldeveloper连接mysql
- 文件基础知识
猜你喜欢

Tkinter GUI address book management system

"Digital security" alert NFT's seven Scams
SQL optimizer parsing | youth training camp notes

MySQL 索引优化全攻略

Good news! Ruiyun technology was awarded the member unit of 5g integrated application special committee of "sailing on the sea"

Creation of unity Bezier curve

Sorting also needs to know the information and linked list

Related operations of binary tree

Auditing related notes

Could not stop Cortex-M device! please check the JTAG cable的解决办法
随机推荐
Auditing related notes
MySQL page lock
Oracle uses impdp import to report an error: ora-39001: invalid parameter value ora-39000: dump file description error ora-39088: file name cannot contain path description
数二2010真题考点
Creation of unity Bezier curve
Redis source code and design analysis -- 15. RDB persistence mechanism
CH582 BLE 5.0 使用 LE Coded 广播和连接
虚拟偶像代言产品出问题谁负责?
Oracle导入出错:IMP-00038: 无法转换为环境字符集句柄
Imx6 rtl8189ftv migration
OV7725 yuv 640*[email protected] 配置文件
Mock服务moco系列(三)- 重定向、正则表达式、延迟、模板、事件、分模块设计
二叉树的相关操作
Keil5 "loading PDSC debug description failed for STMicroelectronics stm32hxxxxxxx" solution
MySQL lost the previous 0 after the decimal number type select
UFT (QTP) - summary points and automated test framework
Redis source code and design analysis -- 16. AOF persistence mechanism
UFT(QTP)-总结点与自动化测试框架
BiSeNet v1
STM8S003F3 uart的使用