coding
unsky
deepdim
thought

id 11. Container With Most Water Add to List QuestionEditorial Solution My Submissions
Total Accepted: 105561
Total Submissions: 293689
Difficulty: Medium
Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.

Note: You may not slant the container.

note:

# 方法二

$$S\left( i,j \right) =\min \left( height\left( i \right) ,height\left( j \right) \right) *\left( j-i \right)$$

$$\left( j’-i’ \right) <\left( j-i \right)$$

$$\min \left( height\left( i \right) ,height\left( j \right) \right)$$

考虑情况

1. 当 $height(i) < height(j)$ 时，对任何 $j’<j$ 来说一定有：

(a) $min(height(i),height(j’))<height(i)=min(height(i),height(j))$

2 . $height(i) > height(j)$ 需要j–;

1. $height(i) =height(j)$ 需要 i++,j–;

note: