File tree 2 files changed +39
-16
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder
2 files changed +39
-16
lines changed Original file line number Diff line number Diff line change 12
12
*/
13
13
public class _11 {
14
14
15
- public int maxArea (int [] height ) {
16
- int max = Integer .MIN_VALUE ;
17
- int len = height .length ;
18
- int i = 0 ;
19
- int j = len - 1 ;
20
- while (i < j ) {
21
- if (Math .min (height [i ], height [j ]) * (j - i ) > max ) {
22
- max = Math .min (height [i ], height [j ]) * (j - i );
23
- }
24
- if (height [i ] <= height [j ]) {
25
- // we need to find the shorter one,
26
- // then calculate its area
27
- i ++;
28
- } else {
29
- j --;
15
+ public static class Solution1 {
16
+ public int maxArea (int [] height ) {
17
+ int max = 0 ;
18
+ int i = 0 ;
19
+ int j = height .length - 1 ;
20
+ while (i < j ) {
21
+ max = Math .max (Math .min (height [i ], height [j ]) * (j - i ), max );
22
+ if (height [i ] <= height [j ]) {
23
+ // we need to find the shorter one,
24
+ // then calculate its area
25
+ i ++;
26
+ } else {
27
+ j --;
28
+ }
30
29
}
30
+ return max ;
31
31
}
32
- return max ;
33
32
}
34
33
35
34
}
Original file line number Diff line number Diff line change
1
+ package com .fishercoder ;
2
+
3
+ import com .fishercoder .solutions ._11 ;
4
+ import org .junit .BeforeClass ;
5
+ import org .junit .Test ;
6
+
7
+ import static junit .framework .Assert .assertEquals ;
8
+
9
+ public class _11Test {
10
+ private static _11 .Solution1 solution1 ;
11
+ private static int [] height ;
12
+
13
+ @ BeforeClass
14
+ public static void setup () {
15
+ solution1 = new _11 .Solution1 ();
16
+ }
17
+
18
+ @ Test
19
+ public void test1 () {
20
+ height = new int []{1 , 1 };
21
+ assertEquals (1 , solution1 .maxArea (height ));
22
+ }
23
+
24
+ }
You can’t perform that action at this time.
0 commit comments