2024-03-19 02:45:09 +08:00

24 lines
403 B
Go

package main
func maxArea(height []int) int {
var left, right, max = 0, len(height) - 1, 0
for left < right {
area := 0
if height[left] > height[right] {
area = height[right] * (right - left)
right--
} else {
area = height[left] * (right - left)
left++
}
if area > max {
max = area
}
}
return max
}
func main() {
println(maxArea([]int{1, 2, 54, 75, 3, 5, 7, 93, 3}))
}