Files
LeetCode-Go/leetcode/0011.Container-With-Most-Water/11. Container With Most Water.go
2020-08-07 17:06:53 +08:00

23 lines
338 B
Go

package leetcode
func maxArea(height []int) int {
max, start, end := 0, 0, len(height)-1
for start < end {
width := end - start
high := 0
if height[start] < height[end] {
high = height[start]
start++
} else {
high = height[end]
end--
}
temp := width * high
if temp > max {
max = temp
}
}
return max
}