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 }