This commit is contained in:
krahets
2026-08-18 03:09:22 +08:00
parent d8c34d88b5
commit ba5285949b
108 changed files with 237 additions and 229 deletions
@@ -1095,7 +1095,7 @@ As shown in Figure 14-20, both time complexity and space complexity are determin
### 4.   Space Optimization
Since each state is only related to the state in the row above it, we can use two arrays rolling forward to reduce the space complexity from $O(n^2)$ to $O(n)$.
Since each state is only related to the state in the row above it, we can use two arrays rolling forward to reduce the space complexity from $O(n \times cap)$ to $O(cap)$.
Further thinking, can we achieve space optimization using just one array? Observing, we can see that each state is transferred from the cell directly above or the cell in the upper-left. If there is only one array, when we start traversing row $i$, that array still stores the state of row $i-1$.