#70
Climbing Stairs
easy· 1-D DPruns: 0You are climbing a staircase with n steps. Each time you can climb 1 or 2 steps. Return the number of distinct ways to climb to the top.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 197
class Solution:
def climbStairs(self, n: int) -> int:
if n <= 2:
return n
a, b = 1, 2
for _ in range(3, n + 1):
a, b = b, a + b
return b
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.