diff --git a/trap.java b/trap.java new file mode 100644 index 0000000..8bf7870 --- /dev/null +++ b/trap.java @@ -0,0 +1,28 @@ +class Solution { + public int trap(int[] height) { + int []rightGtr = new int[height.length]; + int []leftGtr = new int[height.length]; + //left greater + for(int i=0; i=0; i--) { + if(i==rightGtr.length-1) rightGtr[i]=height[i]; + else + rightGtr[i] = Math.max(rightGtr[i+1], height[i]); + } + // System.out.println(Arrays.toString(rightGtr)); + int water =0; + for(int i=0; i=height[i]) + water += level-height[i]; + + } + + return water; + } +}