Skip to content

Commit 61bbe5f

Browse files
authored
Update README.md
1 parent 74f1997 commit 61bbe5f

File tree

1 file changed

+21
-10
lines changed
  • solution/0000-0099/0011.Container With Most Water

1 file changed

+21
-10
lines changed

solution/0000-0099/0011.Container With Most Water/README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,29 @@ class Solution {
264264

265265
#### C
266266

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;
277270
}
278271

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+
}
279290
```
280291
281292
<!-- tabs:end -->

0 commit comments

Comments
 (0)