Easy DP solution in Java (Similar to fibonacci)


#1

public class Solution {
public int climbStairs(int A) {

        int dp[] = new int[A+1];
        dp[0]=1; // 1 way to climb 0 stairs
        dp[1]=1; //I way  to climb stairs
        
        for(int i=2;i<=A;i++)
            dp[i] = dp[i-1]+dp[i-2];
            
        return dp[A]; //return number of ways to climb A stairs.
    }
}