Leetcode - Climbing Stairs (Python)

preview_player
Показать описание
July 2020 Leetcode Challenge
Leetcode - Climbing Stairs
Рекомендации по теме
Комментарии
Автор

Nice video Tim! I did it recursively.

Can't wait for the next month's challenge

janmichaelaustria
Автор

1:26 thank you for your 💡idea
class Solution:
def climbStairs(self, n: int) -> int:

if n<=3: return n
l = [2, 3]
for i in range(3, n):
l.append(l[-1] + l[-2])
else:
return l[-1]

bhupenderyadav
Автор

I don't know about everyone, but I can't get it into my head how the recurrence relation came up to be f(n) = f(n - 1) + f(n - 2). How did we conclude the resulting num of steps is summing steps at n - 1 with steps at n - 2 🤯

Omar-hwzi
Автор

just wondering isn't that a Fibonacci series? Also with respect to the logic, there is one way to reach 0 step (you basically stand there without climbing). So the series becomes 1, 1, 2, 3, 5, 8 ... In case if n gets bigger wont this particular code result in memory overflow?

naramukuriht
Автор

Why this Code not Working 🤔
If n<=2:
return n
else:
return

Any one Find the solution please clear my doubt 👀🙏🏻

shankhadeepghosh
join shbcf.ru