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;}新闻热点
疑难解答