Skip to content

Commit c15f65b

Browse files
author
weir
committed
update
1 parent 5ae3814 commit c15f65b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.blankj.medium._011.ON;
2+
3+
/**
4+
* 暴力求解
5+
*
6+
* @author weir
7+
*/
8+
@SuppressWarnings("ALL")
9+
public class Slution {
10+
public static void main(String[] args) {
11+
Slution slution = new Slution();
12+
System.out.println("maxArea = " + slution.maxArea(new int[]{1, 1})); //1
13+
System.out.println("maxArea = " + slution.maxArea(new int[]{1,8,6,2,5,4,8,3,7})); /* 49 */
14+
}
15+
16+
public int maxArea(int[] height) {
17+
int maxArea = 0;
18+
for (int i = 0, j = height.length - 1; i < j; ) {
19+
int grap = j - i;
20+
int area = height[i] < height[j] ? grap * height[i++] : grap * height[j--];
21+
maxArea = Math.max(area, maxArea);
22+
}
23+
return maxArea;
24+
}
25+
}

src/_11/Slution.java renamed to src/com/blankj/medium/_0011/ON2/Slution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package _11;
1+
package com.blankj.medium._0011.ON2;
22

33
/**
4+
* 暴力求解
45
* @author weir
56
*/
67
public class Slution {

0 commit comments

Comments
 (0)