Created
August 28, 2020 01:59
-
-
Save AbhiAgarwal192/a947b5c71fcf858749c6a33be2ea1d1e to your computer and use it in GitHub Desktop.
Ways to climb stairs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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