Skip to content

Commit

Permalink
Create: 11-Container-With-Most-Water.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Ykhan799 authored Sep 4, 2022
1 parent 8652eff commit 8141c62
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions c/11-Container-With-Most-Water.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
int maxArea(int* height, int heightSize){
int left = 0;
int right = heightSize - 1;
int res = 0;

while (left < right) {
res = max(res, min(height[left], height[right]) * (right - left));
if (height[left] < height[right]) {
left += 1;
}
else if (height[right] <= height[left]) {
right -= 1;
}
}
return res;
}

// C does not have a predefined min and max function
int max(int a, int b) {
return (a > b) ? a : b;
}

int min(int a, int b) {
return (a < b) ? a : b;
}

0 comments on commit 8141c62

Please sign in to comment.