leetCode 70.Climbing Stairs (爬楼梯) 解题思路和方法
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?
思路:题目也比較简单。类似斐波那契。
代码例如以下:
public class Solution {
public int climbStairs(int n) {
//此题相似斐波那契数列
if(n <= 0){
return 0;
}
if(n <= 1){
return 1;
}
if( n <= 2){
return 2;
}
int i = 3;
int f1 = 1;
int f2 = 2;
int f3 = 0;
while(i++ <= n){
f3 = f1+f2;
f1 = f2;
f2 = f3;
}
return f3;
}
}
leetCode 70.Climbing Stairs (爬楼梯) 解题思路和方法的更多相关文章
- [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 爬楼梯
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爬楼梯
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爬楼梯 (C++)
题目: 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 爬楼梯 (递归,记忆化,动态规划)
题目描述 要爬N阶楼梯,每次你可以走一阶或者两阶,问到N阶有多少种走法 测试样例 Input: 2 Output: 2 Explanation: 到第二阶有2种走法 1. 1 步 + 1 步 2. 2 ...
- 70. Climbing Stairs爬楼梯
网址:https://leetcode.com/problems/climbing-stairs/ 其实就是斐波那契数列,没什么好说的. 注意使用3个变量,而不是数组,可以节约空间. class So ...
- Leetcode#70. Climbing Stairs(爬楼梯)
题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数. 示例 1: 输入: 2 输出: 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 ...
- 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 ...
随机推荐
- C语言-05内存剖析
1.进制 1. 二进制 1> 特点:只有0和1,逢2进1 2> 书写格式:0b或者0b开头 3> 使用场合:二进制指令\二进制文件,变量在内存中就是二进制存储 ...
- 关于回波损耗 和 驻波比的摘要 Return Loss and VSWR
关于回波损耗 和 驻波比的摘要 以下摘自:http://www.soontai.com/cal_rtvswr.html RL = 20log((VSWR+1) / (VSWR-1)) VSWR = ( ...
- [原博客] POJ 2975 Nim 统计必胜走法个数
题目链接题意介绍了一遍Nim取石子游戏,可以看上一篇文章详细介绍.问当前状态的必胜走法个数,也就是走到必败状态的方法数. 我们设sg为所有个数的Xor值.首先如果sg==0,它不可能有必胜走法,输出0 ...
- Java 8 的 JVM 有多快?Fork-Join 性能基准测试
Java 8 已经发布一段时间了,许多开发者已经开始使用 Java 8.本文也将讨论最新发布在 JDK 中的并发功能更新.事实上,JDK 中已经有多处java.util.concurrent 改动,但 ...
- 李洪强iOS开发之-cocopods安装
- 李洪强iOS开发之-Swift_00_介绍
SWIFT (计算机编程语言) Swift,苹果于2014年WWDC(苹果开发者大会)发布的新开发语言,可与Objective-C*共同运行于Mac OS和iOS平台,用于搭建基于苹果平台的应用程序. ...
- 看了一下安装文件. 是qt4python 下用了 webkit,包装了bootstrap
Pg9.6 安装包里的pgadmin4 反正软件是开源的,慢慢看源码呗.
- QWidget与HWND的互相转换
QWidget与HWND的互相转换 在编写Windows的应用程序时,我们有时不可避免地要与Windows平台固有的Win32 API打交道,但是Win32 API里面常常用到的HWND等诸多句柄QT ...
- 【Xamarin挖墙脚系列:移动设备应用的开发周期及准则】
原文:[Xamarin挖墙脚系列:移动设备应用的开发周期及准则] 原文地址:https://developer.xamarin.com/guides/cross-platform/getting_st ...
- linux中nginx的安装,linux的版本是ubutu
linux环境下,安装nginx,报错如下: the HTTP rewrite module requires the PCRE library. 1.需要安装pcre,报一下错误: you need ...