[leetcode] 11. Container With Most Water (medium)
以Y坐标长度作为木桶边界,以X坐标差为桶底,找出可装多少水。
思路:
前后遍历。
Runtime: 5 ms, faster than 95.28% of Java
class Solution {
        public int maxArea(int[] height) {
            int res = 0;
            int beg = 0;
            int end = height.length - 1;
            int temp = 0;
            while (beg != end) {
                temp = Math.min(height[beg], height[end]) * (end - beg);
                res = temp > res ? temp : res;
                if (height[beg] > height[end])
                    end--;
                else
                    beg++;
            }
            return res;
        }
[leetcode] 11. Container With Most Water (medium)的更多相关文章
- Leetcode  11.  Container With Most Water(逼近法)
		11. Container With Most Water Medium Given n non-negative integers a1, a2, ..., an , where each repr ... 
- leetcode 11. Container With Most Water 、42. Trapping Rain Water 、238. Product of Array Except Self 、407. Trapping Rain Water II
		11. Container With Most Water https://www.cnblogs.com/grandyang/p/4455109.html 用双指针向中间滑动,较小的高度就作为当前情 ... 
- 如何装最多的水? — leetcode 11. Container With Most Water
		炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ... 
- 蜗牛慢慢爬 LeetCode 11. Container With Most Water [Difficulty: Medium]
		题目 Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai ... 
- LeetCode 11. Container With Most Water (装最多水的容器)
		Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ... 
- [LeetCode] 11. Container With Most Water 装最多水的容器
		Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ... 
- LeetCode#11. Container With Most Water
		问题描述 Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ... 
- Java [leetcode 11] Container With Most Water
		问题描述: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ... 
- C#解leetcode 11. Container With Most Water
		Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ... 
随机推荐
- C语言宏定义##连接符和#符的使用(MFC就是靠##自动把消息和消息函数对应起来了,借助宏来减少switch case代码的编写量)
			C语言中如何使用宏C(和C++)中的宏(Macro)属于编译器预处理的范畴,属于编译期概念(而非运行期概念).下面对常遇到的宏的使用问题做了简单总结. 关于#和## 在C语言的宏中,#的功能是将其后面 ... 
- Oracle 裁掉北京研发团队,相应职位撤回美国(收购了NetSuite,LogFire,Dyn)
			根据中国日报报道,2017年1月14日上午9点09分,甲骨文北京研发团队的同事收到了来自BU老大的一封邮件.邮件上提及,由于市场变化,甲骨文开始整合各研发中心资源公司在云计算方向发力,文末单独提出了甲 ... 
- 伪元素黑魔法:一个替代onerror解决图片加载失败的方案
			问题的引出是这样的,在一个项目中有大量的页面主体是table做数据展示,所以就封装了一个table的组件,提供动态渲染的方案.有个问题是数据类型中有图片,对于图片的加载失败我们需要做容错.一般我们的思 ... 
- Ruby元编程:动态添加类属性及其实际应用
			上个星期测试道的Monkey老师和我聊到测试用例参数过多的问题,其实这样的问题在我这里也同样经历过.比如我的测试用例必须面对不同的测试环境,每个环境有无数的参数,开发的最初阶段,因为参数少,所以就放在 ... 
- TCP使用注意事项总结
			目录 发送或者接受数据过程中对端可能发生的情况汇总 本端TCP发送数据时对端进程已经崩溃 本端TCP发送数据时对端主机已经崩溃 本端TCP发送数据时对端主机已经关机 某个连接长时间没有数据流动 TCP ... 
- 分布式数据库中间件 MyCat 搞起来!
			关于 MyCat 的铺垫文章已经写了三篇了: MySQL 只能做小项目?松哥要说几句公道话! 北冥有 Data,其名为鲲,鲲之大,一个 MySQL 放不下! What?Tomcat 竟然也算中间件? ... 
- 简洁的描述SpringMVC工作流程
			1.客户端发送来的请求 经过前端控制器(springDispatcherServlet)调用映射器(HandlerMapping)来找到对应的执行链(HandlerExecutionChain)对象, ... 
- Fabric1.4源码解析:客户端创建通道过程
			在使用Fabric创建通道的时候,通常我们执行一条命令完成,这篇文章就解析一下执行这条命令后Fabric源码中执行的流程. peer channel create -o orderer.example ... 
- 无法启动print spooler服务,错误2,系统找不到指定的文件
			来自百度: 无法启动print spooler服务,错误2,系统找不到指定的文件 我的打印机无法运行:出现"打印后台程序没有执行"提示.查:print spooler没有启动.点击 ... 
- JS中闭包的介绍
			闭包的概念 闭包就是能够读取其他函数内部变量的函数. 一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域. 变量的作用域无非就是两种:全局变量和局部变量. Javascri ... 
