Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
費式數列
1 2 3 4 5 6 7 8 9 10 | int climbStairs(int n) { int stair[n+1]; stair[0]=1; stair[1]=1; // stair[2]=2; for(int i=2;i<=n;i++){ stair[i]=stair[i-1]+stair[i-2]; } return stair[n]; } |
沒有留言:
張貼留言