Algorithm Puzzles: Climbing Stairs
everyday every week sometimes: Climbing Stairs
Puzzle from leetcode:
You are climbing a staircase. It takes n steps to reach the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
It’s an easy puzzle can be resolved via dynamic programming:
- dp = 1
- dp = 2
- dp = dp + dp
- dp[n] = dp[n-1] + dp[n-2]
TC should be O(n) and SC should be O(1).