bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 70. Climbing Stairs

70. Climbing Stairs

Leetcode Solutions

Dynamic Programming Approach

  1. Initialize an array dp of size n + 1 to store the number of ways to reach each step.
  2. Set dp[0] to 1 and dp[1] to 1, since there is only one way to reach the first step (either step 0 or step 1).
  3. Iterate from 2 to n, and for each i, set dp[i] to dp[i-1] + dp[i-2].
  4. The value of dp[n] will be the answer, which is the number of distinct ways to climb to the top.
UML Thumbnail

Recursion with Memoization Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...