一、题目
力扣原题:https://leetcode-cn.com/problems/trapping-rain-water/submissions/
二、暴力
class Solution {
public int trap(int[] height) {
if (null == height || 0 == height.length) {
return 0;
}
int result = 0;
for (int i = 1; i < height.length - 1; i++) {
// 找到左边界
int left = i - 1;
int leftVal = height[left];
while (left >= 0) {
leftVal = Math.max(leftVal, height[left]);
left--;
}
// 找到右边界
int right = i + 1;
int rightVal = height[right];
while (right < height.length) {
rightVal = Math.max(rightVal, height[right]);
right++;
}
// 计算当前位