Force link :https://leetcode-cn.com/probl...
Their thinking :
- The problem of receiving rainwater is a classic problem in the array , Let's first point out the key algorithms : Double pointer
- The next step is the old way , Analyze the problem stem , From the title we can see , Because the subscript of the array can be regarded as the abscissa , The value of an array can be thought of as an ordinate , Therefore, it holds the most rain , In fact, it is the largest area that can be enclosed in the array , How to calculate the maximum area ? It's long * high , That is, the maximum area that the array subscript and value can enclose
- Use double pointer , The slow pointer points to the array header , The fast pointer points to the end of the array , The area is a fast pointer subscript - The product of the slow pointer subscript and the smaller of the two subscripts , Record this value , Replace this value when there is a larger value
- Array if traversal , Naturally, the shorter ones move towards the middle , Until the two hands meet
func maxArea(height []int) int {
n := len(height)
l, r, max := 0, n-1, 0
for l < r {
m := (r - l) * min(height[l], height[r])
if max < m {
max = m
}
if height[l] < height[r] {
l++
} else {
r--
}
}
return max
}
func min(x, y int) int {
if x < y {
return x
}
return y
}
func max(x, y int) int {
if x > y {
return x
}
return y
}






![[NLP] vector retrieval model landing: Bottleneck and solution!](/img/c4/784534e5504dfee1c989d19255c31b.jpg)

