思路
双指针
每次移动较矮的那一边
题解
func maxArea(height []int) int {
res := 0
left,right := 0, len(height) - 1
for left != right {
temp := minHeight(height[left],height[right]) * (right - left)
res = maxAns(res,temp)
if height[left] > height[right] {
right--
} else {
left++
}
}
return res
}
func maxAns(a,b int) int {
if a > b {
return a
}
return b
}
func minHeight(a,b int) int {
if a > b {
return b
}
return a
}