11. Container With Most Water
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相关推荐
- 【贪心+双指针】LeetCode 11. Container With Most Water
LeetCode 11. Container With Most Water Solution1: 参考网址:http://www.cnblogs.com/grandyang/p/4455109.ht ...
- 【LeetCode】11. Container With Most Water 解题小结
题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...
- LeetCode 11.Container With Most Water
题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...
- LeetCode 11 Container With Most Water
问题:给出一个数组nums,要求选择2个,使得容器中包含的水最多. 思路:假设选取x,y,其中x<y,则包含的水为min(x,y)*(index(y) - index(x)).此时应该选择在最小 ...
- leetcode 11. Container With Most Water
题意:题目大概意思就是让你找两个数使得两个数的最小值乘以他们的距离最大Area 题解:设置两个变量, 一个是从头开始,一个是从尾开始,计算两个数的Area,并更新最大值,如果开始的元素大于结尾的元素则 ...
- LeetCode 11. Container With Most Water--Java 解法--困雨水简单版
LeetCode 11. Container With Most Water–Java 解法 此文首发于我的个人博客:LeetCode 11. Container With Most Water–Ja ...
- Container with most water(盛水最多的容器)
Container with most water(盛水最多的容器) 简单的证明 如图 题目: 给定 n 个非负整数 a1,a2,-,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n ...
- leetcode -eleven:Container With Most Water
2019独角兽企业重金招聘Python工程师标准>>> Given n non-negative integers a1, a2, ..., an, where each repre ...
- C#LeetCode刷题之#11-盛最多水的容器(Container With Most Water)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3615 访问. 给定 n 个非负整数 a1,a2,...,an,每 ...
最新文章
- P4281 [AHOI2008]紧急集合 / 聚会
- 【转】webshell检测——使用auditd进行system调用审计
- IT专家经验教训分享: 我犯过的九件大错
- 如何去写一手好 SQL?
- 网络爬虫框架cetty的实现
- spring boot使用外置tomcat部署需增加如下初始化类
- oracle数据量大时候分区索引思路
- 视频领域的Instagram:Viddy用户突破2600万
- java 多层异常_Java多层嵌套异常处理的基本流程
- 信息学奥赛一本通 2061:【例1.2】梯形面积
- Spring Cloud学习笔记-009
- 第三届蓝桥杯决赛c++b组
- ArcGIS 城市生活区用地适宜性评价(一)
- 可以用树结构表达版本号
- 学习C++程序设计需要什么基础
- 00900网页设计与制作多选题
- 2021-04-30 AndroidStudio_3种按钮点击事件_小白龙抄作业
- android 图片/视频混合轮播控件banner
- 轨道交通通信施工学习总结(四)漏泄同轴电缆安装
- 热议!211高校近200名硕博新生开学无宿舍住,需校外租房...
热门文章
- helloword,认真就输了
- PKU A Simple Problem with Integers 3468
- vmware Failed to initialize remote display subsystem
- JavaEE6入门02—Myeclipse8.5+GlassFish
- android自定义数字键盘和字母键盘,Android自定义键盘的实现(数字键盘和字母键盘)...
- java jstat gc_分析JVM GC及内存情况的方法
- SpringSecurity用数据库信息做认证
- Eureka-服务发现
- 斗地主案例的需求分析
- 方法引用_通过super引用父类的成员方法