Skip to content

Commit 8141c62

Browse files
authored
Create: 11-Container-With-Most-Water.c
1 parent 8652eff commit 8141c62

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

c/11-Container-With-Most-Water.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
int maxArea(int* height, int heightSize){
2+
int left = 0;
3+
int right = heightSize - 1;
4+
int res = 0;
5+
6+
while (left < right) {
7+
res = max(res, min(height[left], height[right]) * (right - left));
8+
if (height[left] < height[right]) {
9+
left += 1;
10+
}
11+
else if (height[right] <= height[left]) {
12+
right -= 1;
13+
}
14+
}
15+
return res;
16+
}
17+
18+
// C does not have a predefined min and max function
19+
int max(int a, int b) {
20+
return (a > b) ? a : b;
21+
}
22+
23+
int min(int a, int b) {
24+
return (a < b) ? a : b;
25+
}

0 commit comments

Comments
 (0)