[Leetcode]011. Container With Most Water
public class Solution {
public int maxArea(int[] height) {
int left = 0, right = height.length - 1;
int maxArea = 0;
while (left < right) {
maxArea = Math.max(maxArea, Math.min(height[left], height[right]) * (right - left));
if (height[left] < height[right])
left++;
else
right--;
}
return maxArea;
}
}
[Leetcode]011. Container With Most Water的更多相关文章
- 【JAVA、C++】LeetCode 011 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
炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...
- No.011 Container With Most Water
11. Container With Most Water Total Accepted: 86363 Total Submissions: 244589 Difficulty: Medium Giv ...
- LeetCode--No.011 Container With Most Water
11. Container With Most Water Total Accepted: 86363 Total Submissions: 244589 Difficulty: Medium Giv ...
- LeetCode OJ Container With Most Water 容器的最大装水量
题意:在坐标轴的x轴上的0,1,2,3,4....n处有n+1块木板,长度不一,任两块加上x轴即可构成一个容器,其装水面积为两板的间距与较短板长之积,以vector容器给出一系列值,分别代表在0,1, ...
- 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(逼近法)
11. Container With Most Water Medium Given n non-negative integers a1, a2, ..., an , where each repr ...
- 【LeetCode】011 Container With Most Water
题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...
- [LeetCode][Python]Container With Most Water
# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/container-with-most-water/ Given n non-neg ...
随机推荐
- .net Core 2.1 MVC+EF+Redis搭建
官方学习资料 搭建空MVC框架 1.创建一个空模板 2.创建文件夹 Controllers.Models.Views 3.在Controllers文件夹下创建HomeController.cs 选择C ...
- 【LeetCode】023. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 题 ...
- RTSP协议分析(二)
以下是某省IPTV的RTSP协商过程: DESCRIBE rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp?playtype=1& ...
- Poj 1504 Adding Reversed Numbers(用字符串反转数字)
一.题目大意 反转两个数字并相加,所得结果崽反转.反转规则:如果数字后面有0则反转后前面不留0. 二.题解 反转操作利用new StringBuffer(s).reverse().toString() ...
- 【转】Pro Android学习笔记(三六):Fragment(1):基本概念
目录(?)[-] 为何引入Fragment 大小屏幕的适配 横屏竖屏切换 返回键 什么是Fragment 为何引入Fragment 我们之前的Activity都是都是全屏处理较为简单的单一事务功能,适 ...
- sql中in和exist语句的区别?(补充了left join和right join)
in和exists(摘录自百度)in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询. 如果两个表中一个较小,一个是大表,则子查询表大的用exi ...
- mysql查询语句例题
1.一条SQL语句查询两表中两个字段 首先描述问题,student表中有字段startID,endID.garde表中的ID需要对应student表中的startID或者student表中的endID ...
- WCF服务用户名密码访问
有2种方式, 第一直接在程序中指定用户名密码,配置调用 private void BtnSearch_Click(object sender, EventArgs e) { try { var cli ...
- mysql-日志种类
MySQL有以下几种日志: 1,错误日志:记录启动.运行或停止时出现的问题,一般也会记录警告信息. 2,一般查询日志:记录建立的客户端连接和执行的语句. 3,慢查询日志:记录所有执行时间超过lo ...
- Hadoop YARN配置参数剖析(3)—MapReduce相关参数
MapReduce相关配置参数分为两部分,分别是JobHistory Server和应用程序参数,Job History可运行在一个独立节点上,而应用程序参数则可存放在mapred-site.xml中 ...