Accepted Java iterative solution


  • 1
    A
    public int climbStairs(int n) {
            if(n<=2) return n;
    
            int prev = 1,result = 2;
            while(n-->2){
                result = prev + result;
                prev = result - prev;
            }
            return result;
        }

Log in to reply
 

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