My java solution


  • 2
    L
    public int climbStairs(int n) {
        int f1 = 1;
        int f2 = 2;
        for(int i = 3; i <= n; i++){
            if(i%2 == 0) f2 = f1+f2;
            else f1 = f1 + f2;
        }
        return n%2 == 0 ? f2 : f1;
    }

Log in to reply
 

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