mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-27 02:27:12 +00:00
build
This commit is contained in:
@@ -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$.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user