70. 爬楼梯

    xiaoxiao2021-03-25  108

    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?

    Note: Given n will be a positive integer.

    思想:斐波那契数列问

     

    public int climbStairs(int n){ int[] fib=new int[n+1]; fib[0]=1; fib[1]=1; for(int i=2;i<=n;i++){ fib[i]=fib[i-2]+fib[i-1]; } return fib[n]; }

     

     

     

     

     

     

    转载请注明原文地址: https://ju.6miu.com/read-21314.html

    最新回复(0)