Container With Most Water(C++)
class Solution {
public:
int maxArea(vector<int>& height)
{
int l=0,r=height.size()-1;
int area=0;
while(l<r)
{
area=max(area,min(height[l],height[r])*((r-l)));
if(height[l]<height[r])
l++;
else
r--;
}
return area;
}
};
Container With Most Water(C++)相关推荐
- 【贪心+双指针】LeetCode 11. Container With Most Water
LeetCode 11. Container With Most Water Solution1: 参考网址:http://www.cnblogs.com/grandyang/p/4455109.ht ...
- Container with most water(盛水最多的容器)
Container with most water(盛水最多的容器) 简单的证明 如图 题目: 给定 n 个非负整数 a1,a2,-,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n ...
- leetcode -eleven:Container With Most Water
2019独角兽企业重金招聘Python工程师标准>>> Given n non-negative integers a1, a2, ..., an, where each repre ...
- C#LeetCode刷题之#11-盛最多水的容器(Container With Most Water)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3615 访问. 给定 n 个非负整数 a1,a2,...,an,每 ...
- 【LeetCode】11. Container With Most Water 解题小结
题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...
- LeetCode 11.Container With Most Water
题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...
- LeetCode 11 Container With Most Water
问题:给出一个数组nums,要求选择2个,使得容器中包含的水最多. 思路:假设选取x,y,其中x<y,则包含的水为min(x,y)*(index(y) - index(x)).此时应该选择在最小 ...
- leetcode - Container With Most Water
题目链接:http://oj.leetcode.com/problems/container-with-most-water/ 第一个解法是用两个数组双向记录.方法的时间复杂度是O(n+max).这里 ...
- LeetCode11:Container With Most Water
public int MaxArea(int[] height) {int start=0;int end=height.Length-1;int max=0;while(start<end){ ...
- [leetcode] Container With Most Water
思路:最大面积等于两条垂直线中较小的一条乘以与x轴相交的长度,可以使用Two Pointers,一个从数组头开始(记为i),一个从数组尾部开始(记为j),当i < j时,一直循环找最大面积,如果 ...
最新文章
- win10 c盘清理_win10 C盘爆红怎么清理?
- OpenCASCADE:Foundation Classes之数学原语和算法
- hadoop中两种上传文件方式
- 论文浅尝 | 面向视觉常识推理的层次语义增强方向图网络
- python的workbook_python openpyxl 操作 excel
- Java™ 教程(原子变量)
- [ZT]ASP.NET中如何防范SQL注入式攻击
- 设计模式(六)原型模式
- 数据挖掘原理与实践学习(3)
- 高端游戏计算机配置单,全球最顶级的游戏电脑配置 高端游戏电脑装机推荐
- 0xl c语言中003是整形常量,整型常量
- 五,FreeRTOS之——相对延时与绝对延时
- 数据脱敏:保障数据安全的脱敏方案
- 6S大气校正模型源码
- Ubuntu桌面右键不管用解决办法
- DateFormat 线程安全
- SpringBoot整合Redis配置MyBatis二级缓存
- ESP8266+micropython+HCSR04 超声波测距传感器
- 【锐捷无线】AC热备配置
- 网页设计之栅格系统及应用
热门文章
- Three.js中的矩阵
- 堆排序算法(C#实现)
- hibernate中实体类对象的四种状态
- 菜鸟学Linux 第048篇笔记 配置slave server
- Linux 小知识翻译 - 目录 (完结)
- 国内趋于概念化的 “数据分析”在硅谷是怎样真正落地的?
- 设置vim默认显示行号
- 电信运营商推出1号2卡的应用设计
- 【COCOS2DX-LUA 脚本开发之十二】Hybrid模式-利用AssetsManager实现在线更新脚本文件lua、js、图片等资源(免去平台审核周期)...
- wordpress配置HTTPS遇到问题解决方案