11. Container With Most Water
2021-01-21 本文已影响0人
jluemmmm
- Runtime: 84 ms, faster than 75.66%
- Memory Usage: 41.6 MB, less than 13.80%
容器中可以最大装水数,双指针法进行实现
/**
* @param {number[]} height
* @return {number}
*/
var maxArea = function(height) {
let start = 0
let end = height.length - 1
let cur = 0
let max = 0
while (start < end) {
if(height[start] > height[end]) {
cur = (end - start) * height[end]
end--
} else {
cur = (end - start) * height[start]
start++
}
if(cur > max) max = cur
}
return max
};