WRong solution at LeetCode
class Solution {
public int maxArea(int[] height) {
int n = height.length;
int res = 0;
for(int i = 1; i < n ; i++){
// finding left maximum
int lMax = height[0];
for( int j = 0; j < i; j++){
lMax = Math.max(height[j], lMax);
}
// Finding right maximum
int rMax = height[n-1];
for(int j = i + 1; j < n ; j++) {
rMax = Math.max(height[j], rMax);
}
res = res + Math.min(lMax, rMax) - height[i];
}
return res;
}
}
Comments
Post a Comment