Climbing Stairs leetcode problem solution DP-
n = 2 2 There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps
n = 3 3 There are three ways to climb to the top. 1. 1 step + 1 step + 1 step 2. 1 step + 2 steps 3. 2 steps + 1 step
This problem can be solved by using dp.
Since we know we can climb 1 step or 2 step at a time so our current solution depends on n-1 or n-2 steps solution,
let's say we are at ith stair. we can react at ith stair from i-1 th stair and i-2th stair.
Here is my code-