> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Climbing Stairs Python Solution with Tests

> Tested Python solution for LeetCode 70 with 17 pytest cases. Generate a practice environment with lcpy.

LeetCode 70, [Easy](https://leetcode-py.wisl.dev/catalog/easy.md). Topics: [Math](https://leetcode-py.wisl.dev/catalog/topics/math), [Dynamic Programming](https://leetcode-py.wisl.dev/catalog/topics/dynamic-programming), [Memoization](https://leetcode-py.wisl.dev/catalog/topics/memoization). [View on LeetCode](https://leetcode.com/problems/climbing-stairs/description/).

Generate this problem as a practice environment: tested reference solution, 17 [parametrized pytest cases](https://leetcode-py.wisl.dev/practice/testing.md), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 70   # by problem number
lcpy gen -s climbing_stairs   # by problem name
```

## Problem

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?

### Examples

```
Input: n = 2
Output: 2
```

**Explanation:** There are two ways to climb to the top.

1. 1 step + 1 step
2. 2 steps

```
Input: n = 3
Output: 3
```

**Explanation:** 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

### Constraints

* 1 \<= n \<= 45

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/climbing_stairs/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/climbing_stairs/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n)
    # Space: O(1)
    # This follows Fibonacci pattern
    # Standard Fib: F(0)=0, F(1)=1, F(2)=1, F(3)=2, F(4)=3, F(5)=5...
    def climb_stairs(self, n: int) -> int:
        if n <= 2:
            return n

        prev2, prev1 = 1, 2
        for _ in range(3, n + 1):
            current = prev1 + prev2
            prev2, prev1 = prev1, current

        return prev1
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(1) |

## Tags

[Grind 75](https://leetcode-py.wisl.dev/catalog/grind-75.md), [Grind](https://leetcode-py.wisl.dev/catalog/grind.md), [Blind 75](https://leetcode-py.wisl.dev/catalog/blind-75.md), [NeetCode 150](https://leetcode-py.wisl.dev/catalog/neetcode-150.md), [NeetCode 250](https://leetcode-py.wisl.dev/catalog/neetcode-250.md), [NeetCode All](https://leetcode-py.wisl.dev/catalog/neetcode.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.