Advertisement
Ways to Reach the n'th Stair
JavaView on GFG
Ways to Reach the n'th Stair.java
Java
class Solution {
int countWays(int n) {
int dp[] = new int[n + 1];
dp[0] = 1;
for (int i = 1; i <= n; i++) {
dp[i] += dp[i - 1];
if (i > 1)
dp[i] += dp[i - 2];
}
return dp[n];
}
}
Advertisement
Was this solution helpful?