Easy understanding Java solution using iterative


  • 0
    V
     public int climbStairs(int n) {
        int solution;
        int[] solutions = new int[n + 2];
        solutions[1] = 1;
        solutions[2] = 2;
    
        for (int i = 3; i <= n; i++) {
            solutions[i] = solutions[i-2]+solutions[i-1];
        }
        return solutions[n];
    }

Log in to reply
 

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