Skip to content

Commit 74f1997

Browse files
authored
Update Solution.c
1 parent 59289cf commit 74f1997

File tree

1 file changed

+19
-6
lines changed
  • solution/0000-0099/0011.Container With Most Water

1 file changed

+19
-6
lines changed
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
int maxArea(int* h, int n) {
2-
int l = 0, r = n - 1, max = 0;
1+
int min(int a, int b) {
2+
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;
312
while (l < r) {
4-
int area = (r - l) * (h[l] < h[r] ? h[l++] : h[r--]);
5-
if (area > max)
6-
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+
}
720
}
8-
return max;
21+
return ans;
922
}

0 commit comments

Comments
 (0)