leetcode 70. Climbing Stairs

来源:互联网 发布:Java中log4j的用法 编辑:程序博客网 时间:2024/06/05 08:29
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.

an=an1+an2
a0=a1=1

public class Solution {    public int climbStairs(int n) {        int a = 1, b = 1;        while(--n>0){            a = (b+=a) - a;        }        return b;    }}
原创粉丝点击