My C++ version ,very concise


  • 0
    T
    int climbStairs(int n) 
    {
        int a,b;
        a=b=1;
        for(int i=2;i<=n;++i)
        {
            int tmp=b;
            b=a+b;
            a=tmp;
        }
        return b;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.