2019独角兽企业重金招聘Python工程师标准>>>

就是说,x轴上在1,2,...,n点上有许多垂直的线段,长度依次是a1, a2, ..., an。找出两条线段,使他们和x抽围成的面积最
大。面积公式是 Min(ai, aj) X |j - i|   最简单的做法,for循环两次,时间复杂度是O(N的平方)
public int maxArea(int[] height) {int n = height.length;int maxArea = 0;int i = 0;int j = n-1;while(i<j){int temp = (j - i)*(height[i]>height[j]?height[j]:height[i]);//每次面积if(height[i] < height[j])  //木板低的一方移动{i++;}else{j--;}if(maxArea < temp){maxArea = temp;}}return maxArea;}

转载于:https://my.oschina.net/datacube/blog/702443

11. Container With Most Water相关推荐

  1. 【贪心+双指针】LeetCode 11. Container With Most Water

    LeetCode 11. Container With Most Water Solution1: 参考网址:http://www.cnblogs.com/grandyang/p/4455109.ht ...

  2. 【LeetCode】11. Container With Most Water 解题小结

    题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...

  3. LeetCode 11.Container With Most Water

    题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...

  4. LeetCode 11 Container With Most Water

    问题:给出一个数组nums,要求选择2个,使得容器中包含的水最多. 思路:假设选取x,y,其中x<y,则包含的水为min(x,y)*(index(y) - index(x)).此时应该选择在最小 ...

  5. leetcode 11. Container With Most Water

    题意:题目大概意思就是让你找两个数使得两个数的最小值乘以他们的距离最大Area 题解:设置两个变量, 一个是从头开始,一个是从尾开始,计算两个数的Area,并更新最大值,如果开始的元素大于结尾的元素则 ...

  6. LeetCode 11. Container With Most Water--Java 解法--困雨水简单版

    LeetCode 11. Container With Most Water–Java 解法 此文首发于我的个人博客:LeetCode 11. Container With Most Water–Ja ...

  7. Container with most water(盛水最多的容器)

    Container with most water(盛水最多的容器) 简单的证明 如图 题目: 给定 n 个非负整数 a1,a2,-,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n ...

  8. leetcode -eleven:Container With Most Water

    2019独角兽企业重金招聘Python工程师标准>>> Given n non-negative integers a1, a2, ..., an, where each repre ...

  9. C#LeetCode刷题之#11-盛最多水的容器(Container With Most Water)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3615 访问. 给定 n 个非负整数 a1,a2,...,an,每 ...

最新文章

  1. P4281 [AHOI2008]紧急集合 / 聚会
  2. 【转】webshell检测——使用auditd进行system调用审计
  3. IT专家经验教训分享: 我犯过的九件大错
  4. 如何去写一手好 SQL?
  5. 网络爬虫框架cetty的实现
  6. spring boot使用外置tomcat部署需增加如下初始化类
  7. oracle数据量大时候分区索引思路
  8. 视频领域的Instagram:Viddy用户突破2600万
  9. java 多层异常_Java多层嵌套异常处理的基本流程
  10. 信息学奥赛一本通 2061:【例1.2】梯形面积
  11. Spring Cloud学习笔记-009
  12. 第三届蓝桥杯决赛c++b组
  13. ArcGIS 城市生活区用地适宜性评价(一)
  14. 可以用树结构表达版本号
  15. 学习C++程序设计需要什么基础
  16. 00900网页设计与制作多选题
  17. 2021-04-30 AndroidStudio_3种按钮点击事件_小白龙抄作业
  18. android 图片/视频混合轮播控件banner
  19. 轨道交通通信施工学习总结(四)漏泄同轴电缆安装
  20. 热议!211高校近200名硕博新生开学无宿舍住,需校外租房...

热门文章

  1. helloword,认真就输了
  2. PKU A Simple Problem with Integers 3468
  3. vmware Failed to initialize remote display subsystem
  4. JavaEE6入门02—Myeclipse8.5+GlassFish
  5. android自定义数字键盘和字母键盘,Android自定义键盘的实现(数字键盘和字母键盘)...
  6. java jstat gc_分析JVM GC及内存情况的方法
  7. SpringSecurity用数据库信息做认证
  8. Eureka-服务发现
  9. 斗地主案例的需求分析
  10. 方法引用_通过super引用父类的成员方法