Climbing Stairs
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?
用递归到n = 44 时 会超时 根据菲波那切数列进行计算 n阶梯子爬法是n-1 和 n-2 阶梯子的总和
1 int climbStairs(int n) { 2 int a = 1; 3 int b = 2; 4 int i,c; 5 if(1 == n) 6 return 1; 7 if(2 == n) 8 return 2; 9 for(i = 2; i < n; i++) 10 { 11 c = a + b; 12 a = b; 13 b = c; 14 } 15 return c; 16 }