You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
603 B
36 lines
603 B
3 years ago
|
/**
|
||
|
* @param {number[]} height
|
||
|
* @return {number}
|
||
|
*/
|
||
|
|
||
|
/*
|
||
|
volume = maxHeight * distance
|
||
|
*/
|
||
|
var maxArea = function(height) {
|
||
|
let maxVolume = 0;
|
||
|
let maxA = 0;
|
||
|
let maxB = 1;
|
||
|
|
||
|
for (let i = 0; i < height.length -1; ++i){
|
||
|
for (let j = i+1; j < height.length; ++j){
|
||
|
let volume = getVolume(height[i], height[j], j - i);
|
||
|
|
||
|
if (volume > maxVolume){
|
||
|
maxVolume = volume;
|
||
|
maxA = i;
|
||
|
maxB = j;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return maxVolume;
|
||
|
};
|
||
|
|
||
|
function getVolume(a, b, distance){
|
||
|
let height = Math.min(a, b);
|
||
|
|
||
|
let volume = height * distance;
|
||
|
|
||
|
return volume;
|
||
|
}
|