LeetCode p42 Trapping Rain Water 题解
1.题目:
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
For example,
Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.
题意:
给你一个数组,是每个坐标上砖块的高度,为这组砖块最多可以盛多少水。
2.解题思路:
两个指针,分别从左右出发,原理类似于俄罗斯方块,慢慢消掉被堆满的底层~
具体见代码。
3.代码
1 |
|