Climbing Stairs

 https://leetcode.com/problems/climbing-stairs/

class Solution {
public:
    int dp[46];
    int climbStairs(int n) {
       if(dp[n]!=0)return dp[n];
       if(n==2) {
           dp[n]=2;
           return 2;
       }
       if(n==1){
           dp[n]=1;
         return 1;  
       }
     
        dp[n]= climbStairs(n-1)+climbStairs(n-2);
        return dp[n];
    }
};

Comments

Popular posts from this blog

Perfect Peak of Array

Is Rectangle?

Sort array with squares!