Code
Recursion with memoization
Time Complexity: O(n), Space Complexity: O(n)
Bottom up DP
Time Complexity: O(n), Space Complexity: O(n)
Buttom up DP with constant space
Time Complexity: O(n), Space Complexity: O(1)
可以觀察到 table[i]
只和 table[i+1]
and table[i+2]
有關係。
Link