> For the complete documentation index, see [llms.txt](https://chiragjain.gitbook.io/neetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chiragjain.gitbook.io/neetcode/70-climbing-stairs/code.md).

# CODE

```python
class Solution:
    def climbStairs(self, n: int) -> int:
        if n < 3:
            return n
        second_last_step, last_step = 1, 2
        # For a given postion you can reach it by 
        # 1 step + number of way you reached last step
        # 2 step + number of way you reached second last step
        # 1 and 2 are possible moves given in question hence the equation
        for _ in range(3, n + 1):
            second_last_step, last_step = last_step, (second_last_step + last_step)
        return last_step
            
        
```
