/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* max water
* @param arr int整型一维数组 the array
* @return long长整型
*/
function maxWater( arr ) {
// write code here
let leftMax = 0;
let rightMax = 0;
let left = 0;
let right = arr.length-1;
let result = 0;
while(left<right){
leftMax = Math.max(leftMax,arr[left]);
rightMax = Math.max(rightMax,arr[right]);
if(arr[left]<arr[right]){
result+=leftMax-arr[left];
left++;
}else{
result +=rightMax - arr[right];
right--;
}
}
return result;
}
module.exports = {
maxWater : maxWater
};