[LeetCode][Array] 11. Container With Most Water

UDS 诊断 - CommunicationControl(通信控制)(0x28)服务 诊断 字节参数名称字节值#1CommunicationControl(通信控制)请求SID0x28#2#3communicationType(通信类型)#4nodeIdentificationNumer(节点标识符)(高位字节)controlType 为 0x04 或 0x05 时,使用该参数#5nodeIdentificationNumer(节点标识符)(低位字节)controlType 为 0x04 或 0x05 时,使用该参数。 阅读详情

Problems: https://leetcode.com/problems/container-with-most-water/

Solution1:
Brute Force

class Solution {
    public int maxArea(int[] height) {
        int maxContainer = 0;
        for(int i = 0; i < height.length; i++) {
            for(int j = i + 1; j < height.length; j++) {
                maxContainer = Math.max(maxContainer, (j-i) * Math.min(height[i], height[j]));
            }
        }
        return maxContainer;
    }
}

Solution2:
双指针,起始位left在最左,right在最右,比较height[left], height[right],取较小的值进行运算,并将较小值的index向里移动一位

class Solution {
    public int maxArea(int[] height) {
        int maxArea = 0, left = 0, right = height.length - 1;
        while(left < right) {
            maxArea = Math.max(maxArea, Math.min(height[left], height[right]) * (right - left));
            // 只有移动较小的height值,maxArea才可能变得更大
            if (height[left] < height[right]) {
                left++;
            } else {
                right--;
            }
        }
        return maxArea;
    }
}
你的小程序地图功能还只是“摆设”吗?支付宝地图API的深度玩法都在这里了! 🏆本文收录于《滚雪球学支付宝小程序开发》专栏,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家关注&&收藏&&订阅!持续更新中,up!up!up!! 阅读详情

相关推荐

《UE4游戏开发》之 《查cook资源失败,问题记录》

当项目打包时,cook出错,但是从原始引擎提供的信息中,没有提示具体的那个资源出错,要查到出错资源,还是非常麻烦。 下面就材质cook出错,增加一些日志,方便查找问题做简单记录 材质cook的一个阶段,是收集MaterialShaderMap,如果在这个阶段收集的信息出错,将会在FShaderMapContent::GetOutdatedTypes函数中,因为Shaders指针指向的内存有问题而出错,通过断点发现,FShaderMapContent这个类对象指针为null,而这个类对象的来源于AllMat.

qq_21919621的博客 2583

LeetCode Array 11 Container With Most Water

11. Container With Most Water Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at ...

Yi Jiao's Blog 168

5G核心网NAS消息解析:从协议字段到实际抓包分析(附Wireshark示例)

本文深入解析5G核心网NAS消息的实战分析方法,从协议字段解读到实际Wireshark抓包诊断。通过详解扩展协议鉴别器、安全头类型、流程事务标识等核心字段,并结合注册流程故障排查实例,指导工程师快速定位NAS层问题,提升5G网络调试与协议分析效率。

grass的博客 538

LeetCode Array Medium 11. Container With Most Water

Description Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at ...

baobo4566的博客 163

用deepseek对GPU服务器进行压力测试

利用 DeepSeek 模型对 GPU 服务器进行压力测试,核心思路是通过,验证 GPU 服务器在计算、显存、网络等维度的承载能力,同时观察稳定性与性能瓶颈。

weixin_42795092的博客 1618

WebUI自动化测试框架搭建(python+pytest+selenium+allure)

将鼠标移动到要定位的元素上面>右键>点击“检查”>在元素代码上右键>复制>复制XPath。

m0_63729339的博客 1288

Leetcode array 11. Container With Most Water

Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two...

owenfy的博客 193

宝塔面板+pbootCMS建站全流程:从服务器选购到上线优化(附常见问题排查)

本文提供了一份详尽的宝塔面板与pbootCMS建站实战指南。内容涵盖从云服务器选购、宝塔面板部署与安全加固,到pbootCMS安装、权限配置、数据库连接等核心步骤。同时深入讲解了PHP环境优化、Nginx伪静态设置、缓存开启等性能与SEO优化技巧,并附有常见问题排查与后期维护建议,帮助用户高效、稳健地完成专业网站构建。

e4f5g6h的博客 669

【leetcode】#11 Container With Most Water【Array】【Medium】

11.Container With Most Water Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis ...

Rongyan97718的博客 283

ADS 使用调整器动态调参教程(Tuning)

ADS动态调参教程

weixin_42845306的博客 1万+

基于Python的二手奢侈品电商平台商品保值率数据爬取与分析

本文旨在探讨如何利用Python网络爬虫技术获取二手奢侈品电商平台商品数据,并通过数据分析研究奢侈品的保值率特性。研究将使用最新的爬虫技术(包括Playwright、异步处理和数据清洗技术)来高效获取数据,并利用Pandas、Matplotlib等数据分析库进行深入的数据可视化分析。本文详细介绍了爬虫的设计思路、实现过程以及数据分析方法,为奢侈品投资和消费提供数据参考。关键词:Python爬虫、奢侈品保值率、数据分析、Playwright、异步处理。

2201_76125261的博客 512

leetcode [array] No.11 Container With Most Water

题目描述 Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find...

Richard_M_pu的博客 233

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

LeetCode 11.Container With Most Water Medium/Array

文章目录Container WIth Most Water1.题目描述2.Example3.Solution1.暴力解法2.使用两个指针 Container WIth Most Water 1.题目描述 Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints

押切徹的博客 252

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Leetcode Array 11 Container With Most Water

题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find...

weixin_30332705的博客 97

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

【leetcode】Array——Container With Most Water(11)

题目:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i

永不言败的博客 315

leetcode.array--11. Container With Most Water

题目:11. Container With Most Water 问题描述:https://leetcode.com/problems/container-with-most-water/description/ 最容易的n方超时,于是想想怎么降低 其实对于横坐标为i和j的两条线段(i初始值为0,j初始值为len(height)-1),其最大容积vmax=min(height[i],heig

Nero Zhang的博客 305

[重拾 leetcode - go] [array] 11. Container With Most Water

原题链接 解答这道题的关键就是-木桶可以盛多少水,完全是由短边决定的。 解法一:Brute Force 遍历数组,比较数组任意两个值组合形成的面积的大小。 时间复杂度 O(N^2) 空间复杂度 O(1) 解法二: two pointer 设置两个指针,一个指向数组最左边,一个指向数组最右边 计算数组之间形成的面积值并更新最大值 移动指针,移动原则是:移动二者中较短的那一个(这样才不会给我们带来损...

lin_tuer的博客 206

[array] leetCode-11. Container With Most Water-Medium

leetCode-11. Container With Most Water-Medium descrition Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the tw...

weixin_30587025的博客 145

[Array] Leetcode 11.Container With Most Water 盛水最多的容器 python

题目描述 给定 n 个非负整数 a1,a2,…,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。 说明:你不能倾斜容器,且 n 的值至少为 2。 思路 思路一(暴力的双重循环) 这种实现非常原始,在这里就不赘述了,时间复杂度为...

yeizisn的博客 492

LeetCode_Array_11. Container With Most Water 盛最多水的容器【双指针】【java】【中等】

双指针法的妙用,非常合理

&再见萤火虫&的博客 191

LeetCode-Array-11-M: 盛最多水的容器(Container With Most Water)

文章目录思路解法-双指针 给定 n 个非负整数 a1,a2,…,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。 说明:你不能倾斜容器,且 n 的值至少为 2。 示例: 输入: [1,8,6,2,5,4,8,3,7] 输出: 49 思...

Heorin X的博客 228

leetcode 11. Container With Most Water 、42. Trapping Rain Water 、238. Product of Array Except Self 、...

11. Container With Most Water https://www.cnblogs.com/grandyang/p/4455109.html 用双指针向中间滑动,较小的高度就作为当前情况的高度,然后循环找容量的最大值。 不管两个指针中间有多少高度的柱子,只管两头,因为两头的才决定最大容量。 class Solution { public: int maxAr...

weixin_30673611的博客 127

Google面试题专题3 - leetcode33. Search in Rotated Sorted Array/11. Container With Most Water - 经典

leetcode33. Search in Rotated Sorted Array 面试常考题!(微软、头条和百度) 题目描述 假设一升序数组以某基准数进行旋转。例如[0,1,2,4,5,6,7] → [4,5,6,7,0,1,2] 查找目标数字。如果在数组中出现返回它的索引,否则返回-1. 假设数组中没有重复数字,时间复杂度要求O(logn). 例子 Example 1: Inp...

libh的博客 314

LeetCode 11. Container With Most Water

分析 思路 //左侧从左向右,右侧从右向左 //如果左侧比右侧低,则左侧右侧之间的节点与左侧节点之间面积不必计算;//容器高度按左侧计算,宽度不及到右侧的宽度//可直接左侧右移 //如果右侧壁左侧第,则左侧右侧之间的节点与右侧节点之间面积不必计算。//可直接右侧左移 难度 Medium 来源 https://leetcode.com/problems/container-with-most-wat...

ov流岚vo的专栏 268

python Array 11. Container With Most Water

leetcode 11.装最多的水 算法思想:要尽可能装多的水,只能使两边的高度大于或等于中间的高度,使用两个指针,分别从数组的前后指,取最小高度乘上宽度则为所求。 代码: class Solution(object): def maxArea(self, height): """ :type height: List[int] :rtype...

ZHANGWENJUAN1995的博客 201

Leetcode-11. Container With Most Water

Topic Background You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the co

swz_study 769
上一篇: [LeetCode][Array]121. Best Time to Buy and Sell Stock
下一篇: [LeetCode][Array] 53. Maximum Array
Shlyan
博客等级 码龄9年 0粉丝 98原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值