Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 70 Climbing Stairs - Implementation

The code

Now, head to LeetCode 7070 and implement the memoized solution yourself. Try writing it from scratch without looking at the code provided. Think through the recurrence relation, identify the base cases, then add memoization. The implementation follows directly from the recurrence. Time complexity: O(n)O(n).

Space complexity: O(n)O(n) for the memoization table storing each subproblem result.