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 @@ -264,18 +264,29 @@ class Solution {
264
264
265
265
#### C
266
266
267
- ``` C
268
-
269
- int maxArea (int * h, int n) {
270
- int l = 0, r = n - 1, max = 0;
271
- while (l < r) {
272
- int area = (r - l) * (h[ l] < h[ r] ? h[ l++] : h[ r--] );
273
- if (area > max)
274
- max = area;
275
- }
276
- return max;
267
+ ``` c
268
+ int min (int a, int b) {
269
+ return a < b ? a : b;
277
270
}
278
271
272
+ int max(int a, int b) {
273
+ return a > b ? a : b;
274
+ }
275
+
276
+ int maxArea(int* height, int heightSize) {
277
+ int l = 0, r = heightSize - 1;
278
+ int ans = 0;
279
+ while (l < r) {
280
+ int t = min(height[ l] , height[ r] ) * (r - l);
281
+ ans = max(ans, t);
282
+ if (height[ l] < height[ r] ) {
283
+ ++l;
284
+ } else {
285
+ --r;
286
+ }
287
+ }
288
+ return ans;
289
+ }
279
290
```
280
291
281
292
<!-- tabs:end -->
You can’t perform that action at this time.
0 commit comments