11. Container With Most Water

使用MATLAB/Simulink对一个简单的智能家居温湿度监测与控制系统进行建模和仿真 目录手把手教你学Simulink——基于Simulink的智能家居温湿度监测与控制仿真建模示例一、背景介绍二、所需工具和环境三、步骤详解步骤1:创建Simulink模型步骤2:构建传感器模块步骤3:添加控制器步骤4:构建执行器模块步骤5:连接各部分步骤6:设置仿真参数步骤7:添加观测器步骤8:运行仿真并分析结果四、总结 智能家居系统中的温湿度监测与控制系统是一个典型的物联网(IoT)应用场景,它通过传感器收集环境数据,并根据预设条件自动调节室内温度和湿度以提高居住舒适度。本指南将介绍如何使用MATLAB/S 阅读详情
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 lines, which together with x-axis forms a container, such that the container contains the most water.

Note: You may not slant the container and n is at least 2.

这道题就是一个在第一象线有多个竖线,竖线长度就是高。两条竖线之间距离就是底。求最大面积。不过由于水桶原理,最大面积是由最短的竖线决定的。同时,我们还要考虑底。因为S=底*高。

方法是从两边开始查找,我们尽量要找两条竖线都很高,并且竖线之间距离很远的组合。所以对于中间低的竖线并且近的竖线可以不计算。每次计算完,更新max就可以了。

我写的原始版本:

class Solution {
public:
    int maxArea(vector<int>& height) {
        const int size = height.size();
        if(size < 2)
            return 0;
        int l = 0, r = size - 1;
        int res = 0;
        for(int i=0, j=size-1; i<j; ) {
            if(height[i] > height[l])
                l = i;
            if(height[j] > height[r])
                r = j;
            res = std::max(res, std::min(height[i], height[j]) * (r-l));
            if(height[i] < height[j])
                ++i;
            else
                --j;
        }
        return res;
    }
};

精简版本:

class Solution {
public:
    int maxArea(vector<int>& height) {
        int i = 0, j = height.size() - 1;
        int res = 0;
        while(i < j) {
            int h = std::min(height[i], height[j]);
            res = std::max(res, h * (j - i));
            while(height[i] <= h && i < j) ++i;
            while(height[j] <= h && i < j) --j;
        }
        return res;
    }
};
20.Labview使用子vi进行VI间的数据传递详解(模块化) 子VI(模块化)题主在题注中也提到, 子VI的建立只是为了减少程序的负担,那么我们当使用子VI的时候首先就要明确什么是子VI?什么样的程序可以作为子VI?首先我们来看NI官方给的定义,具体说明如下图所示:题主已经将重点画出来了,在官方的解释中将子VI定义为了模块化,大家可以看到创建模块化子VI的特点在于减少代码重复工作优化了程序的框架结构。把一个代码打包,需要的时候就拎出来让他处理处理,不需要的时候就让它躺在我的列表里就行了也不占用运行空间。那么创建子VI需要需要注意以下几点:①任何一个程序。 阅读详情

相关推荐

针对中文CLIP模型训练失效的解决方案记录

解决了中文CLIP模型无法正确训练的问题

weixin_45906434的博客 1622

【LeetCode】11. Container With Most Water 解题报告

转载请注明出处:http://blog.csdn.net/crazy1235/article/details/51541984Subject 出处:https://leetcode.com/problems/container-with-most-water/ Given n non-negative integers a1, a2, …, an, where each represents

crazy_jack 6050

LRTimelapse Pro v7.0.0 激活版下载安装教程 (延迟摄影后期渲染)

LRTimelapse Pro 是一款优秀的高级延时摄影解决方案,使用将为用户提供最全面的工具和功能,从导入和组织您的延时摄影序列、视觉工作流程、在 LRTimelapse 中直接编辑和渲染、视觉去闪烁等等,功能齐全,可以使用 LRTimelapse Pro 编辑多个序列时显著提高您的效率,轻松在 LRTimelapse 中配置和使用色彩管理,进行长期延时编辑,在 LRTimelapse Pro 中使用长期工作流程。为延时编辑、关键帧、分级和渲染提供最全面的解决方案。

wyqshusan的博客 3467

【LeetCode】解题11:Container With Most Water

LeetCode解题 11:Container With Most Water Problem 11: Container With Most Water [Medium]解题思路1. 暴力求解2. 双指针Solution (Java) Problem 11: Container With Most Water [Medium] Given n non-negative integers a1, ...

Fayedily的博客 251

从0到1做AI漫剧:即梦+豆包+剪映+红果全流程实战

AI视频生成正在重塑内容创作的生产方式,它让原本高门槛的影视制作,变成了一条由文本、画面、剪辑与分发环节协同的流水线。理解其底层原理,在于将大模型的语义理解、图像生成与视频合成能力,与工程化的流程管理相结合,从而实现从创意到成片的自动化输出。这种技术的价值,不仅体现在降低制作成本,更在于让个人创作者能够独立完成高质量短剧,并快速迭代内容。在短剧、短视频、广告营销等场景中,利用即梦生成画面、豆包编写剧本、剪映完成剪辑、红果进行分发的组合,已成为一种被广泛验证的实践路径。本文聚焦AI漫剧制作,从环境准备、分镜设

weixin_34072637的博客 387

树莓派4B安装 ubuntu20.04 & VNC远程桌面 & 安装ROS noetic

树莓派4B安装ubuntu20.04 & VNC远程桌面1、安装ubuntu方式1:下载Imager文件。方式2:下载镜像文件。2、查询树莓派 IP 地址3、使用ssh远程登录树莓派4、更新源地址5、更新6、安装桌面环境7、允许root登陆8、登陆远程桌面9、设置中文 1、安装ubuntu 方式1:下载Imager文件。...

weixin_44415639的博客 2万+

11.Container With Most Water

题目: LeetCode: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 end...

dbb191379的博客 105

【无人机路径规划】基于强化学习实现多无人机路径规划

【无人机路径规划】基于强化学习实现多无人机路径规划

k8291121的博客 1659

Leetcode 11. Container With Most Water

题目描述:找出两个柱子,使其两根柱子面积最大,就是找两个数,使两个面积最大,就是宽*高最大。 题目链接:Leetcode 11. Container With Most Water 子串、子数组的题目,暴力求解,列举子集之后就可以得出结果,不断更新。 还有一个C++的解法那就是左右指针,如何向左向右条件如下。 代码如下 class Solution { public int maxA...

Za七杂⑧ 206

华为HCIE之TS部分整理

TroubleShooting 整体拓扑 1. MSTP 题目需求:site1 中,CLIENT1 属于 VLAN12,CLIENT3 属于 VLAN34;MSTP 中的 VLAN12 属于 instance1,vlan34 属于 instance2;两个 instance 的主备根桥分别在 SW1 和 SW2 上,并且要求 CLIENT1访问 R1 时经过的路径是 SW3-SW1-R1;同时要求 CLIENT3 访问 R1 时经过的路径是SW3-SW2-R1; 排错思路: ①查看SW3 SW1 SW

ledrsnet的博客 5759

uniapp - 实现 App 端 “半屏幕“ 连续扫码功能,页面只有半个屏幕是扫码框并且可持续连续扫码获取数据(不使用官方 uni.scanCode API,因为无法连续扫码!)详细示例源码插件教程

uniapp app端实现半屏幕扫码,uniapp 扫一扫半个屏幕,uniapp 扫一扫,uniapp持续扫码实现,uniapp怎么自定义扫码和连续扫码,uni-app App端半屏连续扫码,uniapp 扫一扫半个屏幕,uniapp自定义扫码页面样式,实现连续扫码功能(uniapp),uniapp - 实现 App 端 "半屏幕" 连续扫码功能,页面只有半个屏幕是扫码框并且可持续连续扫码获取数据(不使用官方 uni.scanCode API,因为无法连续扫码!)详细示例源码插件教程。

✅ 精选推荐文章 1万+

Leetcode11:Container With Most Water

Leetcode11 Container With Most Water Container With Most Water The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container ...

qq_24367757的博客 189

金融数字化——详解2025年金融智能体深度应用报告【附全文阅读】

《2025年金融智能体深度应用报告》显示,金融智能体已实现80%部署率,推动行业效率提升30%-50%。报告指出智能体通过"感知-推理-规划-执行-进化"机制突破大模型局限,在风控、客服、投研等100+场景实现自动化。典型案例显示,工商银行信贷审批效率提升60%,蚂蚁数科智能客服解决80%问题。尽管面临系统协同、标准缺失等挑战,未来趋势将向多模态交互、自主进化和ESG投资等方向拓展。

cdfunlove的博客 207

Leetcode 11 Container With Most Water

Leetcode 11 Container With Most Water class Solution{ public: int maxArea(vector&lt;int&gt;&amp; height){ int left = 0; int right = height.size()-1; int max_area = 0; while(right &g...

自己的学习笔记 202

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

leetcode记录11.Container With Most Water

leetcode记录11.Container With Most Water # # @lc app=leetcode id=11 lang=python3 # # [11] Container With Most Water # # https://leetcode.com/problems/container-with-most-water/description/ # # algorithm...

我的博客 214

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

leetcode解题报告11. Container With Most Water

leetcode解题报告11. Container With Most Water题目地址 难度是medium题目描述原文: Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that th

sysu_xiaoming的博客 274

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

[leetcode]11. Container With Most Water

[leetcode]11. Container With Most Water Analysis 是阴天呢—— [每天刷题并不难0.0] Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn s...

weixin_32135877的博客 146

LeetCode11. Container With Most Water

11. 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

u010217031的博客 323

LeetCode:11. Container With Most Water

LeetCode: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 li...

Wisimer 218

Leetcode - 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 the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a cont.

xin_rong的博客 147

[leetcode] 11. Container With Most Water @ python

原题 https://leetcode.com/problems/container-with-most-water/ 解法 参考: 花花酱 LeetCode 11. Container With Most Water 双指针法, 水桶的面积用min(height[l], height[r])*(r-l)求得, 难点在于如何移动两个指针, 由于两个指针往中间移的时候, 宽度会降低, 我们需要找到更...

闲庭信步 336

leetcode 11. Container With Most Water

因为一些事情已经有两天没刷leetcode了,从今天开始加油!一切都会慢慢变好的。 今日份leetcode 11. Container With Most Water Description: Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n...

weixin_39979073的博客 438

leetcode11. Container With Most Water两根柱子围成最大面积

牛客网第一课第三题 问题:给定一个非负数的数组,数组中的每个值代表一个柱子的高度,柱子的宽度是1。两个柱子之间可以围成一个面积,规定:面积=两根柱子的最小值*两根柱子之间的距离。 例子:数 组[3,4,2,5]。3和4之间围成的面积为0,因为两个柱子是相邻的,中间没有距离。3和 2之间围成的面积为2,因为两个柱子的距离为1,且2是最短的柱子,所以面积=1*2。3和5之间围成的面积为6,因为两个

穷理何须格物的博客 983

LeetCode-11 Container With Most Water(容器装水最大量)

LeetCode-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 e

你若嘻哈过盛,别人就不再欣赏你的认真 705

leetcode题目11. Container With Most Water

leetcode题目11. Container With Most WaterNote:Example:CODE: #题目简介 Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that ...

zydapangzi的博客 209
上一篇: 63. Unique Paths II[dp]
下一篇: 13. Roman to Integer
FreeeLinux
博客等级 码龄11年 421粉丝 356原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值