We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 59289cf commit 74f1997Copy full SHA for 74f1997
solution/0000-0099/0011.Container With Most Water/Solution.c
@@ -1,9 +1,22 @@
1
-int maxArea(int* h, int n) {
2
- int l = 0, r = n - 1, max = 0;
+int min(int a, int b) {
+ return a < b ? a : b;
3
+}
4
+
5
+int max(int a, int b) {
6
+ return a > b ? a : b;
7
8
9
+int maxArea(int* height, int heightSize) {
10
+ int l = 0, r = heightSize - 1;
11
+ int ans = 0;
12
while (l < r) {
- int area = (r - l) * (h[l] < h[r] ? h[l++] : h[r--]);
- if (area > max)
- max = area;
13
+ int t = min(height[l], height[r]) * (r - l);
14
+ ans = max(ans, t);
15
+ if (height[l] < height[r]) {
16
+ ++l;
17
+ } else {
18
+ --r;
19
+ }
20
}
- return max;
21
+ return ans;
22
0 commit comments