跳到主要内容

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.

For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.

Trapping Rain Water

分析

对于每个柱子,找到其左右两边最高的柱子,该柱子能容纳的面积就是min(left_peak, right_peak) - height

代码

# Python code snippet with just "# TODO"
# TODO

相关题目