首页 > 学院 > 开发设计 > 正文

LeetCode 70. Climbing Stairs

2019-11-08 02:02:11
字体:
来源:转载
供稿:网友

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?

Note: Given n will be a positive integer.

程序代码:

int climbStairs(int n) { int TwoStep=1,OneStep=1,i,sum=0; if(n==1) sum = 1; for(i=2;i<=n;i++) { sum = TwoStep+OneStep; TwoStep = OneStep; OneStep= sum; } return sum;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表