mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 07:01:18 +08:00
Refactor dynamic programming approach of Trapping Rain Water problem.
This commit is contained in:
parent
f07e96ec59
commit
26239f9a97
@ -74,7 +74,7 @@ the sides minus its own height.
|
|||||||
|
|
||||||
- Initialize `answer = 0`
|
- Initialize `answer = 0`
|
||||||
- Iterate the array from left to right:
|
- Iterate the array from left to right:
|
||||||
- Initialize `max_left = 0 and `max_right = 0`
|
- Initialize `max_left = 0` and `max_right = 0`
|
||||||
- Iterate from the current element to the beginning of array updating: `max_left = max(max_left, height[j])`
|
- Iterate from the current element to the beginning of array updating: `max_left = max(max_left, height[j])`
|
||||||
- Iterate from the current element to the end of array updating: `max_right = max(max_right, height[j])`
|
- Iterate from the current element to the end of array updating: `max_right = max(max_right, height[j])`
|
||||||
- Add `min(max_left, max_right) − height[i]` to `answer`
|
- Add `min(max_left, max_right) − height[i]` to `answer`
|
||||||
|
Loading…
Reference in New Issue
Block a user