【LeetCode】70Climbing Stairs

来源:互联网 发布:产品宣传手册制作软件 编辑:程序博客网 时间:2024/05/01 11:02

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;    }}
0 0