爬楼梯

假设你正在爬楼梯,需要n步你才能到达顶部。但每次你只能爬一步或者两步,你能有多少种不同的方法爬到楼顶部?

 
样例

比如n=3,1+1+1=1+2=2+1=3,共有3中不同的方法

返回 3

public class Solution {
    /**
     * @param n: An integer
     * @return: An integer
     */
    public int climbStairs(int n) {
        // write your code here
       int a=1,b=1,c=0;
       if(n==1||n==0)
         return 1;
       while(--n>0)
          {
              c=a+b;
              b=a;
              a=c;
          }
            
        return c;
    }
}

原文地址:https://www.cnblogs.com/lq1500802008/p/6524495.html