Skip to content
CodeItRaw
Code Reading
/
Staircase
Path
Play
Daily
Leaderboard
tr
Bug Hunt
Staircase
How many ways up n stairs, one or two steps at a time? ways(4) should be 5 but returns 0. Find the line and the kind of bug.
Click the line you think is wrong.
1
def
ways
(n):
2
dp = [
0
] * (n +
1
)
3
dp[
0
] = dp[
1
] =
1
4
for
i
in
range
(
2
, n):
5
dp[i] = dp[i -
1
] + dp[i -
2
]
6
return
dp[n]