leetcode 70
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;
}
};
leetcode 70的更多相关文章
- [LeetCode] 70. Climbing Stairs 爬楼梯问题
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- LeetCode 70. 爬楼梯(Climbing Stairs)
70. 爬楼梯 70. Climbing Stairs 题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意: 给定 ...
- 42. leetcode 70. Climbing Stairs
70. Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time y ...
- Leetcode#70. Climbing Stairs(爬楼梯)
题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数. 示例 1: 输入: 2 输出: 2 解 ...
- LeetCode 70 Climbing Stairs(爬楼梯)(动态规划)(*)
翻译 你正在爬一个楼梯. 它须要n步才干究竟顶部. 每次你能够爬1步或者2两步. 那么你有多少种不同的方法爬到顶部呢? 原文 You are climbing a stair case. It tak ...
- 算法题之Climbing Stairs(leetcode 70)
题目: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either cl ...
- LeetCode(70)题解: climbing-stairs
https://leetcode.com/problems/climbing-stairs/ 题目: You are climbing a stair case. It takes n steps t ...
- LN : leetcode 70 Climbing Stairs
lc 70 Climbing Stairs 70 Climbing Stairs You are climbing a stair case. It takes n steps to reach to ...
- [LeetCode] 70. Climbing Stairs 爬楼梯
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
随机推荐
- python深入走路
Python描述符(descriptor)解密 http://www.geekfan.net/7862/
- 加密--win7下安装openssl
http://www.cnblogs.com/ZhouL3777/archive/2012/10/21/2732890.html http://www.cnblogs.com/ZhouL3777/ar ...
- bug_ _ _android.app.Fragment$InstantiationException 解决办法
在实际的开发中,我遇到过两次android.app.Fragment$InstantiationException报错. 其中一次报错,根据报错提示 “make sure class name exi ...
- Java代码规范、格式化和checkstyle检查配置文档
http://www.blogjava.net/amigoxie/archive/2014/05/31/414287.html 文件下载: http://files.cnblogs.com/files ...
- PHP框架 Laravel Eloquent ORM 批量插入数据 && 批量更新目前没有
foreach ($products as $v=>$a) { $count[] = array('product_name' => $a['name'], 'product_weight ...
- 树莓派自身摄像头的opencv调用
很多人知道,opencv不能直接对树莓派原装摄像头进行调用,因为raspicam不是V4L驱动,怎样才能使用树莓派原装摄像头,它可比多数usb摄像头清晰和小巧. 具体方法,给树莓派原装摄像头安装一个可 ...
- java小程序实例 闰年
判断闰年. package com.test; import java.util.Scanner; import org.junit.Test; public class TestRunNian { ...
- [Flex] PopUpButton系列 —— 设置弹出菜单与主按钮之间的间隔
<?xml version="1.0" encoding="utf-8"?><!--设置弹出菜单与主按钮之间的间隔 PopUpButtonPo ...
- sikuli
1.sikuli和selenium集成问题,用java封装一个方法去操作web页面上的一些无法定位的控件 http://bbs.csdn.net/topics/390720479/ 2.关于Siku ...
- Linux命令 find和mv的结合使用:查找文件,移动到某个目录
显示前十个文件 [root@localhost smgpbi]# ls -1 | sort -u | head -10 1.首先查看文件个数,进入所在的文件 # find . -name " ...