LeetCode 11. Container With Most Water

public class Solution {
    public int maxArea(int[] height) {
        int l = 0;
    	int r = height.length - 1;
    	int max = 0;
    	while (l < r) {
    		max = Math.max(max, Math.min(height[l], height[r]) * (r - l));
    		if (height[l] < height[r]) l++;
    		else r--;
    	}
        return max;
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章