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;}
|
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注