Skip to content

Commit a64bb13

Browse files
author
MouCoder
committed
LeetCode--最多盛水量(提交成功,时间复杂度较高且空间复杂度较高)
1 parent b9a16e6 commit a64bb13

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

water/Solution.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package LeetCode.Array.water;
2+
3+
public class Solution {
4+
public int maxArea(int[] height) {
5+
int max = 0,min = 0;
6+
for(int i = 0;i < height.length - 1;i++)
7+
for(int j = i+1;j < height.length;j++){
8+
if(height[i] < height[j])
9+
min = height[i];
10+
else min = height[j];
11+
if(max < (j - i)*min)
12+
max = (j - i)*min;
13+
}
14+
return max;
15+
}
16+
}
17+
//{1,8,6,2,5,4,8,3,7}

water/Test.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package LeetCode.Array.water;
2+
3+
public class Test {
4+
public static void main(String[] args) {
5+
Solution sol = new Solution();
6+
int[] height = {1,8,6,2,5,4,8,3,7};
7+
System.out.println(sol.maxArea(height));
8+
}
9+
}

0 commit comments

Comments
 (0)