Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/azl397985856/leetcode
Browse files Browse the repository at this point in the history
  • Loading branch information
lucifer committed Jan 29, 2020
2 parents a10551b + 23f48f8 commit 128213c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions problems/42.trapping-rain-water.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ for(let i = 0; i < height.length; i++) {
}

```
如上图那么h为 [1, 1, 2, 2, ,2 ,2, ,3, 2, 2, 2, 1]

问题转化为求h,那么h[i]又等于`左右两侧柱子的最大值中的较小值`,即
`h[i] = Math.min(左边柱子最大值, 右边柱子最大值)`

如上图那么h为 [0, 1, 1, 2, 2, 2 ,2, 3, 2, 2, 2, 1]

问题的关键在于求解`左边柱子最大值``右边柱子最大值`,
我们其实可以用两个数组来表示`leftMax`, `rightMax`
以leftMax为例,leftMax[i]代表i的左侧柱子的最大值,因此我们维护两个数组即可。
Expand Down

0 comments on commit 128213c

Please sign in to comment.