mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-23 09:51:45 +08:00
23 lines
338 B
Go
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
|
|
}
|