LintCode:M-装最多水的容器
来源:互联网 发布:深圳软件产业园 编辑:程序博客网 时间:2024/06/05 11:44
LintCode链接
给定 n 个非负整数 a1, a2, ..., an, 每个数代表了坐标中的一个点 (i, ai)
。画 n 条垂直线,使得 i 垂直线的两个端点分别为(i, ai)
和(i, 0)
。找到两条线,使得其与 x 轴共同构成一个容器,以容纳最多水。
注意事项
容器不可倾斜。
样例
给出[1,3,2]
, 最大的储水面积是2
.
标签
public class Solution { /* * @param heights: a vector of integers * @return: an integer */ public int maxArea(int[] heights) { int n=heights.length; if(n==0) return 0; int max=Integer.MIN_VALUE; int i=0, j=n-1; while(i<j){ max = Math.max(max, Math.min(heights[i],heights[j])*(j-i)); if(heights[i]>heights[j]) j--; else i++; } return max; }}
阅读全文
1 0
- LintCode:M-装最多水的容器
- LintCode-装最多水的容器
- lintcode-装最多水的容器-383
- LintCode:装最多水的容器
- lintcode,装最多水的容器
- Lintcode 装最多水的容器
- Lintcode 装最多水的容器
- 装最多水的容器-LintCode
- lintcode刷题——装最多水的容器
- [LintCode 383] 装最多水的容器(Python)
- 装最多水的容器
- 装最多水的容器
- 装最多水的容器
- 装最多水的容器
- 装最多水的容器
- LintCode_383_装最多水的容器
- Java实现-装最多水的容器
- Container With Most Water(能装最多水的容器)
- MBProgressHUD的customView大小问题
- 高性能网站架构设计之缓存篇(6)- Redis 集群命令
- Gradle 系列第二讲-android studio中的四个Gradle相关文件讲解
- CTF web题总结--php函数漏洞
- android studio sonar 配置
- LintCode:M-装最多水的容器
- Java Websocket实例
- 乱码问题
- js 数组去重
- Java中堆内存和栈内存详解
- Using Advanced REST Client to test REST Request.
- 卧底付费专栏盗版群一个月,我们聊聊付费内容的地下黑产
- Jquery 获取对象的几种方式介绍
- 【软件激活】Lightroom6软件及激活