File tree Expand file tree Collapse file tree 1 file changed +21
-10
lines changed
solution/0000-0099/0011.Container With Most Water Expand file tree Collapse file tree 1 file changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -261,18 +261,29 @@ class Solution {
261261
262262#### C
263263
264- ``` C
265-
266- int maxArea (int * h, int n) {
267- int l = 0, r = n - 1, max = 0;
268- while (l < r) {
269- int area = (r - l) * (h[ l] < h[ r] ? h[ l++] : h[ r--] );
270- if (area > max)
271- max = area;
272- }
273- return max;
264+ ``` c
265+ int min (int a, int b) {
266+ return a < b ? a : b;
274267}
275268
269+ int max(int a, int b) {
270+ return a > b ? a : b;
271+ }
272+
273+ int maxArea(int* height, int heightSize) {
274+ int l = 0, r = heightSize - 1;
275+ int ans = 0;
276+ while (l < r) {
277+ int t = min(height[ l] , height[ r] ) * (r - l);
278+ ans = max(ans, t);
279+ if (height[ l] < height[ r] ) {
280+ ++l;
281+ } else {
282+ --r;
283+ }
284+ }
285+ return ans;
286+ }
276287```
277288
278289<!-- tabs:end -->
You can’t perform that action at this time.
0 commit comments