LeetCode第十一题-可以装最多水的容器
Container With Most Water
问题简介:通过一个给定数组,找出最大的矩形面积
问题详解:给定一个数组,包含n个非负整数a1,a2,…,an,其中每个表示坐标(i,ai)处的点,绘制n条垂直线,使得线i的两个端点位于(i,ai)和(i,0),找到两条线,它们与x轴一起形成一个矩形,这样矩形就含有最大的面积
注意:数组至少有两个数字
举例:
输入: [1,8,6,2,5,4,8,3,7]
输出: 49

解法一:双层遍历笨方法

复杂度分析:
空间复杂度:O(n2) - 双层遍历
时间复杂度:O(1) - 定义空间是有限次数的
解法二:Two Pointer Approach
数组最左端和最右端开始,缩小更小的一段,逐渐减少来寻找最大面积

复杂度分析:
空间复杂度:O(n) - 遍历一次数组
时间复杂度:O(1) - 定义有限空间
小白刷题之路,请多指教— — 要么大器晚成,要么石沉大海

LeetCode第十一题-可以装最多水的容器的更多相关文章
- [LeetCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- LeetCode随缘刷题之盛最多水的容器
package leetcode.day_01_30; /** * 给你 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点(i,ai) .在坐标内画 n 条垂直线,垂直线 i的两个端 ...
- leecode第十一题(盛最多水的容器)
class Solution { public: int maxArea(vector<int>& height) { int len=height.size();//错过,少了i ...
- [LeetCode] 11. Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ...
- lintcode:装最多水的容器
装最多水的容器 给定 n 个非负整数 a1, a2, ..., an, 每个数代表了坐标中的一个点 (i, ai).画 n 条垂直线,使得 i 垂直线的两个端点分别为(i, ai)和(i, 0).找到 ...
- LeetCode 11. Container With Most Water (装最多水的容器)
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- C#LeetCode刷题之#11-盛最多水的容器(Container With Most Water)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3615 访问. 给定 n 个非负整数 a1,a2,...,an,每 ...
- leetcode刷题11. 盛最多水的容器
做题连接https://leetcode-cn.com/problems/container-with-most-water/submissions/ 本题分为两种方法: 暴力法: int maxAr ...
- LeetCode(11):盛最多水的容器
Medium! 题目描述: 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .画 n 条垂直线,使得垂直线 i 的两个端点分别为 (i, ai) 和 (i, ...
随机推荐
- 一位月薪1.2w的北漂程序员真实生活!
“ 每个人都有一条生活道路.千万人,千万条,各不相同,各有特点.但是并不是好人都有一条好路,坏人都有一坏路.有的时候却恰恰相反.这虽然不是历史的必然,但却是客观社会存在的.今天咱们说的这部书是发生在当 ...
- 《jmeter:菜鸟入门到进阶》系列
jmeter是我从事软件测试工作以来接触的第一个性能测试工具,也是耗费时间精力最多的一个工具,当然,学习jmeter过程中,由于知识储备不够,也顺带学习了很多其他相关的一些知识. 一直有个想法,就是把 ...
- C++笔记-并发编程 异步任务(async)
转自 https://www.cnblogs.com/diysoul/p/5937075.html 参考:https://zh.cppreference.com/w/cpp/thread/lock_g ...
- C# 递归构造树状数据结构(泛型),如何构造?如何查询?
十年河东,十年河西,莫欺少年穷. 学无止境,精益求精 难得有清闲的一上午,索性写篇博客. 首先,我们需要准备一张表,如下范例: create table TreeTable ( TreeId ) no ...
- Grunt自动化构建环境搭建
1.环境准备 需要安装Git.Node.Bower.Grunt.Ruby NodeJS https://nodejs.org/en/ Ruby http://rubyinstaller.org/ ...
- openstack网络基础:网络叠加模式VLAN、VxLAN、GRE
什么是叠加网络1.一个数据包(或帧)封装在另一个数据包内;被封装的包转发到隧道端点后再被拆装.2.叠加网络就是使用这种所谓“包内之包”的技术安全地将一个网络隐藏在另一个 网络中,然后将网络区段进行迁移 ...
- C语言之控制语言:分支和跳转
if语句 #include<stdio.h> int main(void) { const int FREEZING = 0; float temperature; int cold_da ...
- 如何将多个C文件链接在一起----Makefile编写及make指令
需使用GCC编译器,关于MinGW的安装指南:https://people.eng.unimelb.edu.au/ammoffat/teaching/20005/Install-MinGW.pdf 单 ...
- 常见的页面中两个div自适应等高CSS控制
第一种利用dispaly:table,父级div设置dispaly:table子级div设置display: table-cell; 第一种利用dispaly:flex,父级div设置dispaly: ...
- bzoj3277-串
Code #include<cstdio> #include<iostream> #include<cmath> #include<cstring> # ...