Files
leetcode/top-100-liked/5_test.go
T
2026-05-31 01:09:31 +10:00

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}))
}