All Downloads are FREE. Search and download functionalities are using the official Maven repository.

s0011.container.with.most.water.Solution Maven / Gradle / Ivy

package s0011.container.with.most.water;

public class Solution {
    public int maxArea(int[] height) {
        int max_area = -1;
        int left = 0;
        int right = height.length - 1;

        while (left < right) {
            if (height[left] < height[right]) {
                max_area = Math.max(max_area, height[left] * (right - left));
                left++;
            } else {
                max_area = Math.max(max_area, height[right] * (right - left));
                right--;
            }
        }

        return max_area;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy