leetcode 70
2024-10-08 07:25:02
70. Climbing Stairs
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?
此题为典型的菲波那切数列问题;
当n=1时,有1种走法;
当n=2时,有2种走法;
当n=3时,有3种走法;
当n=4时,有5种走法;
......
当n=k时,有你n[k-1] + n[k-2]种走法;
代码如下:
class Solution {
public:
int climbStairs(int n) {
if(n == )
{
return ;
}
if(n == )
{
return ;
}
int a = ;
int b = ;
int c;
for(int i = ; i < n; i++)
{
c = a + b;
a = b;
b = c;
}
return c;
}
};
最新文章
- jQuery 一句代码返回顶部
- rsync+inotify实现远程数据备份
- Android自定义Dialog及其布局
- [入门]bower安装和使用
- [网络配置相关]——ifconfig命令、ip命令、route命令
- [工作积累] error: bad class file magic (cafebabe) or version (0033.0000)
- 笨办法学C 练习
- zepto源码研究 - zepto.js-3 (常用的工具)
- HDU_2057——64位无符号16进制数的运算
- Python 第七篇:socket编程
- SWT实践过程中遇到的问题
- 解决ubuntu更新中断后报错问题
- python开发部署时新增数据库中表的方法
- IT轮子系列(三)——如何显示方法名——Swagger的使用(三)
- JS判断页面加载是否完成
- python接口自动化(十)--post请求四种传送正文方式(详解)
- Java锁与CAS
- 如何安装使用FastReport
- SVM中径向基函数与高斯核的区别 Difference between RBF and Gaussian kernel in SVM
- SpringBoot-服务端参数验证-JSR-303验证框架
热门文章
- ajax实现的无刷新分页代码实例
- SVN---脱离SVN控制
- WCF Windows Service Using TopShelf and ServiceModelEx z
- [原创博文] 用Python做统计分析 (Scipy.stats的文档)
- solr学习之添加文档
- C# BackgroundWorker的使用【转-http://www.cnblogs.com/tom-tong/archive/2012/02/22/2363965.html】
- PS 查看选定图层的高宽
- [SQL] 不知道是什么存储过程
- ListView之setEmptyView的问题
- 启用 CORS 来解决这个问题(ajax跨域请求)