Container With Most Water with Golang

Vo Thanh Tung
Jul 2, 2021

import "math"
func maxArea(height []int) int {
var start = 0
var end = len(height) - 1
var maxArea float64 = 0
var width = end;
for start < end {
maxArea = math.Max(maxArea, math.Min(float64(height[start]), float64(height[end]))* float64(width) )
if(height[start] < height[end] ) {
start++
} else {
end--
}
width--

}
return int(maxArea);
}

https://play.golang.org/p/bTJ6IbcIzb2

--

--