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 class Solution {
public int climbStairs(int n) {
int len = n % 2 == 0 ? n/2 : n/2 + 1;
double sum = 1;
for(int i = 0; i < len; i++){
double temp = n - (i+1);
double temp2 = i+1;
for(int j = 1; j < i+1; j++){
temp = temp*(n - (i+1) - j);
temp2 = temp2*((i+1)-j);
}
sum = sum + temp/temp2;
}
return (int) sum;
}
}