[LeetCode]Container With Most Water
发布日期:2021-11-22 02:48:56 浏览次数:6 分类:技术文章

本文共 731 字,大约阅读时间需要 2 分钟。

Given n non-negative integers a1a2, ..., an, where each represents a point at coordinate (iai). n vertical lines are drawn such that the two endpoints of line i is at (iai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.

Note: You may not slant the container.

题解:从网上看到的,只知道left++,right--,表示不是很懂,没有证明。

public class Solution {    public int maxArea(int[] height) {                if(height == null || height.length ==1)             return 0;       int area =0,max = 0;       int left = 0,right =height.length-1;       while(left
height[right]) right--; else left++; } return max; }}

转载地址:https://blog.csdn.net/zxdfc/article/details/48729253 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:[LeetCode]Search a 2D Matrix
下一篇:[LeetCode]Permutations

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月01日 20时22分36秒