每天一道算法题

105 阅读1分钟

盛最多水的容器

问题描述

var maxArea = function(height) {
  let begin = 0,end = height.length-1,res = 0
  while(begin<=end){
    res = Math.max(res, Math.min(height[begin],height[end])*(end-begin))
    if(height[begin]<height[end]) {begin++}
    else {end--} 
  }
  return res
}