func maxArea(height []int) int {
var result int
var pos_left,pos_right = 0, len(height) - 1
for (pos_left<pos_right && pos_left <len(height) && pos_right > 0){
var cur int
if height[pos_left] < height[pos_right] {
cur = height[pos_left] * (pos_right - pos_left)
pos_left ++
} else {
cur = height[pos_right] * (pos_right - pos_left)
pos_right --
}
if cur > result {
result = cur
}
}
return result
}
有疑问加站长微信联系(非本文作者)