LeetCode 刷题记录: 42. Trapping Rain Water [Python]

原题

https://leetcode.com/problems/trapping-rain-water/

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.

思路

使用双指针,分别从两头往最高处逼近。每次经过刷新左边和右边的最高值,该处结果等于最高值与当前值的差。

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×