[leedcode 70] Climbing Stairs
2015-07-13 22:22
531 查看
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?
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) { //f(n)=f(n-1)+f(n-2);DP int f1=1; int f2=2; /*for(int i=3;i<=n;i=i+2){ f1=f1+f2; f2=f1+f2; } if(n%2==0) return f2; else return f1;*/ // 解法二: if(n==1) return 1; if(n==2) return 2; for(int i=3;i<=n;i++){ int f3=f1+f2; f1=f2; f2=f3; } return f2; } }
相关文章推荐
- HDU 2476 String painter (区间DP)
- icvGetTrainingDataCallback源码详细分析
- icvCreateHaarTrainingData源码详细分析
- [LeetCode] Factorial Trailing Zeroes
- Project Euler:Problem 60 Prime pair sets
- LightOJ 1070 Algebraic Problem (推导+矩阵快速幂)
- OC 基础之----属性
- CPaintDC 、CWindowDC、 CClientDC、 CDC的区别与联系
- Swiper使用方法(向前和向后按钮在swiper-container外面)
- SonarQube安装完后出现SonarQube is under maintenance. Please check back later.
- LOJ 1070 - Algebraic Problem(矩阵快速幂啊)
- 【转载】Foxmail 小技巧 25则 (转载)
- POJ 3691 DNA repair 基于AC自己主动机DP
- 人工智能计算器AI Calculator 3.3.0 详细破解思路&教程
- 在rails中pluck和select和collect区别
- installation error: unknown failure
- copy, retain, assign , readonly , readwrite,strong,weak,nonatomic整理
- HD 1151Air Raid
- LightOJ 1070 - Algebraic Problem 矩阵快速幂
- ubuntu 下配置发送邮件(sendmail/msmtp+mtt)