标签:min solution else leetcode 比较 length pre 暴力 mos
题目链接:https://leetcode-cn.com/problems/container-with-most-water/
//1.双指针
public int maxArea(int[] height) {
int res = 0;
int i = 0;
int j = height.length - 1;
while (i < j) {
int area = (j - i) * Math.min(height[i], height[j]);
res = Math.max(res, area);
if (height[i] < height[j]) {
i++;
} else {
j--;
}
}
return res;
}
//2.暴力
class Solution {
public int maxArea(int[] height) {
int res=0;
for(int i=0; i<height.length-1; i++){
for(int j=i+1; j<height.length; j++){
int aa = (j-i) * Math.min(height[i],height[j]);
res = Math.max(aa,res);
}
}
return res;
}
}
大家如果感兴趣可以前去手搓
本分类只用作个人记录,大佬轻喷.
标签:min solution else leetcode 比较 length pre 暴力 mos
原文地址:https://www.cnblogs.com/xiaofff/p/12723847.html