70. Climbing Stairs (1D-dp)
DP
time: O(n)
space: O(n)
use fib
time: O(n)
space: O(1)
why return second? because our goal is to use 2 varibles to rotate the value, so
first = second
second = third(outcome)
at last second is the result (third)
ex: n = 3
-> ans. = 3 = 2 + 1
first = second = 2
second = outcome = 3
-> ans = second = 3
Last updated