25 lines
451 B
Go
25 lines
451 B
Go
package top100liked
|
|
|
|
import "testing"
|
|
|
|
// https://leetcode.cn/problems/container-with-most-water/?envType=study-plan-v2&envId=top-100-liked
|
|
|
|
func maxArea(height []int) int {
|
|
l := 0
|
|
r := len(height) - 1
|
|
maxArea := 0
|
|
for l < r {
|
|
maxArea = max(maxArea, (r-l)*min(height[l], height[r]))
|
|
if height[l] < height[r] {
|
|
l++
|
|
} else {
|
|
r--
|
|
}
|
|
}
|
|
return maxArea
|
|
}
|
|
|
|
func TestS5(t *testing.T) {
|
|
println(maxArea([]int{1, 8, 6, 2, 5, 4, 8, 3, 7}))
|
|
}
|