package leetcode.day_01_30;

/**
* 给你 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点(i,ai) 。在坐标内画 n 条垂直线,垂直线 i的两个端点分别为(i,ai) 和 (i, 0) 。找出其中的两条线,使得它们与x轴共同构成的容器可以容纳最多的水。
*
* 说明:你不能倾斜容器。
*
* 示例 1:
*
* 输入:[1,8,6,2,5,4,8,3,7]
* 输出:49
* 解释:图中垂直线代表输入数组 [1,8,6,2,5,4,8,3,7]。在此情况下,容器能够容纳水(表示为蓝色部分)的最大值为49。
* 示例 2:
*
* 输入:height = [1,1]
* 输出:1
* 示例 3:
*
* 输入:height = [4,3,2,1,4]
* 输出:16
* 示例 4:
*
* 输入:height = [1,2,1]
* 输出:2
*
* 提示:
*
* n == height.length
* 2 <= n <= 105
* 0 <= height[i] <= 104
*
* @author soberw
* @Classname MaxArea0011
* @Description
* @Date 2022-01-30 21:16
*/
public class MaxArea0011 {
// 超时
// public int maxArea(int[] height) {
// int maxArea = 0;
// for (int i = 0; i < height.length - 1; i++) {
// for (int j = i + 1; j < height.length; j++) {
// maxArea = Math.max(Math.min(height[i], height[j]) * (j - i), maxArea);
// }
// }
// return maxArea;
// }
public int maxArea(int[] height) {
int maxArea = 0;
for (int i = 0, j = height.length - 1; i < j; ) {
maxArea = Math.max(Math.min(height[i], height[j]) * (j - i), maxArea);
if (height[i] < height[j]){
i++;
}else {
j--;
}
}
return maxArea;
}
}

LeetCode随缘刷题之盛最多水的容器的更多相关文章

  1. leetcode刷题11. 盛最多水的容器

    做题连接https://leetcode-cn.com/problems/container-with-most-water/submissions/ 本题分为两种方法: 暴力法: int maxAr ...

  2. LeetCode第十一题-可以装最多水的容器

    Container With Most Water 问题简介:通过一个给定数组,找出最大的矩形面积 问题详解:给定一个数组,包含n个非负整数a1,a2,…,an,其中每个表示坐标(i,ai)处的点,绘 ...

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

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

  4. LeetCode(11):盛最多水的容器

    Medium! 题目描述: 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .画 n 条垂直线,使得垂直线 i 的两个端点分别为 (i, ai) 和 (i, ...

  5. leecode第十一题(盛最多水的容器)

    class Solution { public: int maxArea(vector<int>& height) { int len=height.size();//错过,少了i ...

  6. LeetCode:盛最多水的容器【11】

    LeetCode:盛最多水的容器[11] 题目描述 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为  ...

  7. Java实现 LeetCode 11 盛最多水的容器

    11. 盛最多水的容器 给定 n 个非负整数 a1,a2,-,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0) ...

  8. 力扣Leetcode 11. 盛最多水的容器

    盛最多水的容器 给你 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找 ...

  9. LeetCode---11. 盛最多水的容器(Java)

    11. 盛最多水的容器 题目地址:https://leetcode-cn.com/problems/container-with-most-water/ 给你 n 个非负整数 a1,a2,...,an ...

随机推荐

  1. linux 部署.net core 环境

    Linux版本Ubuntu 16.04 .net core 下载地址:https://dotnet.microsoft.com/download/dotnet-core/2.1 虽然现在现在.net ...

  2. Linux架构中代理服务器配置与负载均衡

    本期内容概要 代理 负载均衡 内容详细 1.代理 1.主要作用: 将流量平均分配 2.代理的方式 01 正向代理 外部想要访问服务器 先找代理 找到之后还需要找服务器 应用:VPN 02 反向代理 外 ...

  3. 如何用微信小程序,每天给自己赚个鸡腿?

    假期如果实在无聊的话,那跟随田同学的脚步上架一个小程序吧. 话说:谁不想拥有一个自己的小程序呢?既可以赚点小钱又可以长长见识. 不懂小程序的小白能不能做出来呢?那来对了,这个教程就是针对小白的. 今天 ...

  4. [Docker] 制作并运行 Nginx 镜像

    环境 操作系统(cat /etc/redhat-release):CentOS Linux release 7.6.1810 (Core) Docker:18.09.6 文件 Dockerfile F ...

  5. SYCOJ2140祝福短信

    题目-祝福短信 (shiyancang.cn) 1 #include<bits/stdc++.h> 2 using namespace std; 3 map<string,bool& ...

  6. 灵雀云入选Gartner 2020中国ICT技术成熟度曲线报告,容器技术处于顶峰

    近日,全球权威咨询分析机构Gartner发布了"2020中国ICT技术成熟度曲线(Hype Cycle for ICT in China, 2020 )"报告,灵雀云作为国内容器和 ...

  7. HTTP协议层面绕过WAF

    最近也是在一直看过waf相关的资料,本次主要是想写写HTTP协议层面过WAF的一些技巧,来与大家一同探讨 原理 给服务器发送payload数据包,使得waf无法识别出payload,当apache,t ...

  8. 图片不清晰?Graphics 高质量绘制

    Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; Graphics ...

  9. Superset SSO改造和自定义宏命令

    目录 背景 关于Superset 需要解决的问题 定制化改造 准备环境 改造OAuth SSO 安装依赖 配置SSO 添加自定义的SecurityManager 运行一下吧 自定义宏命令 开启配置 添 ...

  10. Go 面向对象编程应用

    #### Go 面向对象编程应用前面学习了很多的基础知识,这一节来实际写一个小案例:涉及到的知识: 1. 数组的基本使用2. 结构体3. 切片 4. 方法5. 循环6. 函数返回值(命名返回值,普通返 ...