标签:
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?
int climbStairs(int n) {
int step[n];
int i = 0;
if(n <= 2)
return n;
step[0] = 1;
step[1] = 2;
for(i = 2; i < n; i++)
{
step[i] = step[i - 2] + step[i - 1];
}
return step[i - 1];
}
标签:
原文地址:http://www.cnblogs.com/dylqt/p/5587379.html