/*接雨水,array是柱子高度,不考虑空间:思路是算出每个柱子能存多少水,然后相加;每个柱子存水高度=(左侧最高和右侧最高的最小值)-自身高度*/标签:right,max,雨水,算法,let,array,Math,left From: https://www.cnblogs.com/spySomeOne/p/17495855.html
let array = [0,1,0,2,1,0,1,3,2,1,2,1]
let length = array.length
let allNumber = 0
for(let i=1;i<length-1;i++){
let left_max = 0
let right_max = 0
for(let j=i;j<length;j++){
right_max = Math.max(right_max,array[j])
}
for(let j=i;j>=0;j--){
left_max = Math.max(left_max,array[j])
}
let number = Math.min(left_max,right_max) - array[i]
allNumber = allNumber+number
}