Skip to content

Instantly share code, notes, and snippets.

@AbhiAgarwal192
Created August 28, 2020 01:59
Show Gist options
  • Save AbhiAgarwal192/a947b5c71fcf858749c6a33be2ea1d1e to your computer and use it in GitHub Desktop.
Save AbhiAgarwal192/a947b5c71fcf858749c6a33be2ea1d1e to your computer and use it in GitHub Desktop.
Ways to climb stairs.
public class Solution {
int[] dp;
public int Climb(int stepsLeft){
if(stepsLeft<0){
return 0;
}
if(stepsLeft==1){
return 1;
}
if(stepsLeft==0){
return 1;
}
if(dp[stepsLeft]!=0){
return dp[stepsLeft];
}
dp[stepsLeft] = Climb(stepsLeft-1) + Climb(stepsLeft-2);
return dp[stepsLeft];
}
public int ClimbStairs(int n) {
dp = new int[n+1];
return Climb(n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment