File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
011_container_with_most_water Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ all :
2+ gcc -O2 -o test container.c
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments