标签:round 斐波那契 rgb 微软雅黑 www color cas enum title
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?
public int ClimbStairs(int n) {
if(n == 0)
return 0;
int pre = 0;
int cur = 1;
int tempCur = 0;
for (int i = 1; i <= n; i++)
{
tempCur = cur;
cur = pre + cur;
pre = tempCur;
}
return cur;
}
static public int[] Fibonacci(int n)
{
int[] arr = new int[n+1];
arr[0] = 0;
arr[1] = 1;
for (int i = 2; i < n + 1; i++)
{
arr[i] = arr[i - 1] + arr[i - 2];
}
return arr;
}
70. 爬梯子问题(斐波那契数列)Climbing Stairs
标签:round 斐波那契 rgb 微软雅黑 www color cas enum title
原文地址:http://www.cnblogs.com/xiejunzhao/p/420b858048e643866608d6d60038b6f7.html