#70

Climbing Stairs

pupil · 415 · lc easy +25 · verified · 53.9% accepted · 24,349 likes · top 45%

play →

Description

A staircase has n steps. On each move you may climb either 1 or 2 steps. Return the number of distinct ways to reach the top.

Example 1:

Input: n = 2
Output: 2
Explanation: There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps

Example 2:

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

Code

1
2
3