public static int MaxArea(int[] b)
{
if (b.Length <= 1)
{
return 0;
}
int max = 0;
int l = 0;
int r = b.Length-1;
while (l < r)
{
int min = GetMinInt(b[l], b[r]);
int xAxis = r - l;
int tmpMax = min * xAxis;
if (tmpMax > max)
{
max = tmpMax;
}
if (b[l] > b[r])
{
r--;
}
else
{
l++;
}
}
return max;
}
public static int GetMinInt(int m, int n)
{
return m > n ? n : m;
}
leetcode :https://leetcode.com/problems/container-with-most-water/
最新推荐文章于 2024-07-25 11:05:20 发布