아래의 그래프라면 height 배열은 [1, 8, 6, 2, 5, 4, 8, 3, 7] 입니다.
저 그래프에 물을 담는다고 생각하고,
물을 담을 수 있는 가장 넓은 면적의 값을 반환해주세요.
function getMaxArea(height) {
width = []
final = height[height.length-1]
rlt_list = []
max = 0;
for(let i=0; i<height.length ; i++){
width = []
width.push(final)
width.push(height[i])
//console.log(width)
width.sort()
//console.log(width)
rlt = (width[0])*(height.length-i-1);
//console.log(rlt)
rlt_list.push(rlt)
if(rlt > max){
//console.log("hello")
max = rlt;
}
//console.log(i+": "+width + ": " + rlt)
//return max;
}
console.log(max)
return max;
}
height = [1, 1]
getMaxArea(height)