leetcode 盛水最多的容器(java)

双指针可以变为但指针鸭,每个容器都取决于短的那条边,每次改变那条边就行了

class Solution {
    public int maxArea(int[] height) {
        int maxSize=0;
        int leftIndex=0,RightIndex=height.length-1;
        while(leftIndexmaxSize?Math.min(height[leftIndex],height[RightIndex])*(Math.abs(leftIndex - RightIndex)):maxSize;
            if(height[leftIndex]

你可能感兴趣的:(leetcode 盛水最多的容器(java))