本文主要是介绍每日一题 盛最多水的容器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
. - 力扣(LeetCode)
思路分析:
利用函数的单调性解决这道题两端取最小,最小的往里找就是高不变或者缩小 宽减少 一定是减小的因此这题可以使用左右指针实现
public int maxArea(int[] height) {int left = 0;int right = height.length - 1;int max = 0;int v = 0;while (left != right){if (height[left] > height[right]){v = height[right] * (right - left);right--;}else {v = height[left] * (right - left);left++;}if (max < v){max = v;}}return max;}
这篇关于每日一题 盛最多水的容器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!