importjava.util.*;publicclassSolution{/**
* max water
* @param arr int整型一维数组 the array
* @return long长整型
*/publiclong maxWater (int[] arr){// write code hereint top =0;int max =0;for(int i =0; i < arr.length; i++){if(arr[i]> max){
max = arr[i];
top = i;}}int left =0, right =0;long count =0;//统计最高柱子左边的雨水for(right =1; right < top; right++){if(arr[left]> arr[right]){
count += arr[left]- arr[right];}else{
left = right;}}
right = arr.length-1;//统计最高柱子右边的雨水for(left = arr.length-1;left>top;left--){if(arr[right]> arr[left]){
count += arr[right]- arr[left];}else{
right = left;}}return count;}}