Skip to content

Commit 2fde4f6

Browse files
Water container
Signed-off-by: Leo Ma <begeekmyfriend@gmail.com>
1 parent 5bb595b commit 2fde4f6

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
all:
2+
gcc -O2 -o test container.c
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
static int maxArea(int* height, int heightSize)
5+
{
6+
int min = 0, max = heightSize - 1;
7+
int area_max = 0;
8+
while (min < max) {
9+
int area = (max - min) * (height[min] < height[max] ? height[min] : height[max]);
10+
area_max = area > area_max ? area : area_max;
11+
if (height[min] < height[max]) {
12+
while (++min < max && height[min] <= height[min - 1]) {
13+
continue;
14+
}
15+
} else {
16+
while (min < --max && height[max] <= height[max + 1]) {
17+
continue;
18+
}
19+
}
20+
}
21+
return area_max;
22+
}
23+
24+
int main(int argc, char **argv)
25+
{
26+
int i, count = argc - 1;
27+
int *nums = malloc(count * sizeof(int));
28+
for (i = 0; i < count; i++) {
29+
nums[i] = atoi(argv[i + 1]);
30+
}
31+
printf("%d\n", maxArea(nums, count));
32+
return 0;
33+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy