init
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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}))
|
||||
}
|
||||
Reference in New Issue
Block a user