LeetCode OJ:Climbing Stairs(攀爬台阶)
2024-08-25 04:21:28
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Subscribe to see which companies asked this question
简单的dp问题,代码如下:
class Solution {
public:
int climbStairs(int n) {
if(n <= )
return n;
dp.resize(n + );
dp[] = ;
dp[] = ;
for(int i = ; i < n + ; ++i){
dp[i] += dp[i - ];
dp[i] += dp[i - ];
}
return dp[n];
}
private:
vector<int> dp;
};
java版本代码如下所示:
public class Solution {
public int climbStairs(int n) {
if(n < ) return n;
int dp [] = new int [n+];
dp[] = ;
dp[] = ;
for(int i = ; i <= n; ++i){
dp[i] = dp[i-] + dp[i-];
}
return dp[n];
}
}
最新文章
- 解决VMware虚拟机宿主机与虚拟机通讯慢
- linux 网络编程比较好的文章
- Oracle 恢复被删除的数据,解决误操作删除数据
- CodeForces 688A-Opponents
- NEC学习 ---- 布局 -两列, 右侧定宽,左侧自适应
- The insertion sort algorithm expressed in pseudocode - 插入排序
- Concurrent Assertion
- Android 简单的代码混淆
- 【手打】LZW编码的C/C++实现
- MVC 树节点Table格式授权
- qt 坐标变换
- 用Ajax遍历三级下拉框
- PHPMYWIND4.6.6前台Refer头注入+后台另类getshell分析
- 【Python】【函数式编程】
- vue-cli 项目搭建
- JMeter出现“the target server failed to respond“的解决办法
- js命名空间写法
- VMWare------安装时出现无法将值写入注册表项
- configure: error: You need a C++ compiler for C++ support.
- docker tag 详解
热门文章
- 使用.NET Core和Vue搭建WebSocket聊天室
- SQL.Mysql中Cast()函数的用法
- php AES-128-CBC 加密 通信java
- 20145307《信息安全系统设计基础》第五周学习总结PT2
- 20145331实验四 ";Android开发基础";
- uboot下如何查看内存里的数据
- 内核启动时在挂载ubi文件系统时提示UBIFS error (ubi0:0 pid 1): ubifs_read_superblock: min. I/O unit mismatch
- Can&#39;t connect to any repository: xxxxxx Error writing request body to server
- Java之JNDI详解
- 爬虫框架Scrapy之Spider