Math Fundamentals18 sections · 814 units
Open in Course

Practice - Climbing Stairs

LeetCode 70

You are climbing a staircase with nn steps. Each time you can climb 11 or 22 steps. How many distinct ways can you reach the top?

For example, if n=3n = 3, there are 33 ways: 1+1+11+1+1, 1+21+2, 2+12+1.

Hint: this follows the Fibonacci sequence. If ways[i]ways[i] is the number of ways to reach step ii, then ways[i]=ways[i1]+ways[i2]ways[i] = ways[i-1] + ways[i-2].