Skip to content

Commit b3f6aae

Browse files
author
lucifer
committed
feat: 润色
1 parent 89d9e8b commit b3f6aae

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

problems/42.trapping-rain-water.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ int trap(vector<int>& heights)
171171
2. 初始化左侧和右侧最高的高度都为 0。
172172
3. 比较 height[left] 和 height[right]
173173
174-
- 3.1 如果 height[left] < height[right]
175-
- 3.1.1 如果 height[left] >= left_max, 则当前格子积水面积为(left_max - height[left])
176-
- 3.1.2 否则无法积水,即积水面积为 0
177-
- 3.2 左指针右移一位
178-
179-
- 3.3 如果 height[left] >= height[right]
180-
- 3.3.1 如果 height[right] >= right_max, 则当前格子积水面积为(right_max - height[right])
181-
- 3.3.2 否则无法积水,即积水面积为 0
182-
- 3.4 右指针左移一位
174+
- 3.1 如果 height[left] < height[right], 那么瓶颈在于 height[left],不需要考虑 height[right]
175+
176+
- 3.1.1 如果 height[left] < left_max, 则当前格子积水面积为(left_max - height[left]),否则无法积水,即积水面积为 0。也可将逻辑统一为盛水量为 max(0, left_max - height[left])
177+
- 3.1.2 左指针右移一位。(其实就是左指针的位置的雨水量已经计算完成了,我们移动到下个位置用同样的方法计算)
178+
179+
- 3.2 否则 瓶颈在于 height[right],不需要考虑 height[left]
180+
181+
- 3.2.1 如果 height[right] < right_max, 则当前格子积水面积为(right_max - height[left]),否则无法积水,即积水面积为 0。也可将逻辑统一为盛水量为 max(0, right_max - height[right])
182+
- 3.2.2 右指针右移一位。(其实就是右指针的位置的雨水量已经计算完成了,我们移动到下个位置用同样的方法计算)
183183
184184
### 代码
185185

0 commit comments

Comments
 (0)