My c++ solution 2ms


  • 0
    1
          class Solution {
    public:
        int climbStairs(int n) {
            if(n==1)
              return 1;
            if(n==2)
              return 2;
            int a=1,b=2;
            int result;
            for(int i=3;i<n;i++)
            {
                 a=a+b;
                 i++;
                 if(i<n)
                   b=a+b;
            }
            result=a+b;
            return result;
        }
    };

Log in to reply
 

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