首页 > 代码库 > 爬楼梯

爬楼梯

public class Solution {

    /**

     * @param n: An integer

     * @return: An integer

     */

    public int climbStairs(int n) {

        // write your code here

        int a=0,b=1,sum=0;

        for(int i=0;i<=n;i++){

            if(i==0){

                sum=1;

            }

            else{

                 sum=a+b;

            a=b;

            b=sum;

            }

        }

       System.out.println(sum);

       return 0;

    }

}

爬楼梯