Climbing Stairs
A staircase has n steps. Each move takes you up 1 or 2 steps. In how many different orders of moves can you get from the ground to the top step? Our example: n = 6 — there are 13 ways.
- input
n: the number of steps of a staircase.- returns
- In how many ways you can climb to the top, going up 1 or 2 steps at a time. Two ways differ when their sequences of moves differ.
- constraints
- 1 ≤ n ≤ 45
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {number} n
* @return {number}
*/
function climbStairs(n) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more dynamic programming (dp) problems
- 121Best Time to Buy and Sell StockEasysolve
- 198House RobberMediumsolve
- 322Coin ChangeMediumsolve
- 300Longest Increasing SubsequenceMediumsolve
- 62Unique PathsMediumsolve
- 1143Longest Common SubsequenceMediumsolve
- 53Maximum SubarrayMediumsolve
- 918Maximum Sum Circular SubarrayMediumsolve
- 139Word BreakMediumsolve
- 120TriangleMediumsolve
- 64Minimum Path SumMediumsolve
- 63Unique Paths IIMediumsolve
- 97Interleaving StringMediumsolve
- 72Edit DistanceMediumsolve
- 221Maximal SquareMediumsolve
- 123Best Time to Buy and Sell Stock IIIHardsolve
- 188Best Time to Buy and Sell Stock IVHardsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.