My Traditional java solution(dp bottom up)


  • 0
    C
    public class Solution {
    public int climbStairs(int n) {
        if(n <= 2)
        return n;
        else{
            int [] steps = new int [n+1];
            steps[0]=0;steps[1]=1;steps[2]=2;
            for(int i = 3;i<=(n);i++)
            {
                steps[i] = steps[i-2]+steps[i-1];
            }
            return steps[n];
        }
    }
    

    }


Log in to reply
 

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