Chinaunix首页 | 论坛 | 博客
  • 博客访问: 253822
  • 博文数量: 170
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1709
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-06 18:01
文章分类

全部博文(170)

文章存档

2016年(11)

2015年(130)

2014年(29)

分类: Java

2015-08-28 14:55:46

//
//Climbing Stairs Total Accepted: 66034 Total Submissions: 191740 My Submissions Question Solution 
//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 ClimbStairs {


public static void main(String[] args) {
// TODO Auto-generated method stub


}
public int climbStairs(int n) {
    if(n<=1)
return 1;
int a=1;
int b=1;
int c=0;
for(int i=1;i<n;i++){
c=a+b;
a=b;
b=c;
}
return c;  
 
}


}

阅读(679) | 评论(1) | 转发(0) |
1

上一篇:Sqrt(x)

下一篇:Simplify Path

给主人留下些什么吧!~~

权镜士2015-08-31 16:40:31

牛逼