Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

class Solution{public:int climbStairs(int n){int a=1,b=n&1;for(;n>1;n-=2)a+=b+=a;return a;}};

Only 93 bytes! It can fit in tweet. Can you make shorter solution?

Easily.

struct Solution{int climbStairs(int n){int a=1,b=1;for(;n--;a=b-a)b+=a;return a;}};

Using struct instead of class saved 6 bytes, using the simpler algorithm saved 4 more.

struct

class

I do like your two-steps-at-once way, though.

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