Trapping Rain Water
Given_n_non-negative integers representing an elevation map where the width of each bar is1, compute how much water it is able to trap after raining.

Example
Given[0,1,0,2,1,0,1,3,2,1,2,1], return6.
分析:
左右两边定边界比较高度,哪边低从哪边开始,然后比较中间的。
然后顺序loop,cur低的话就累加入res,cur高的话作为标杆,更新标杆。
Last updated
Was this helpful?