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第十一题-可以装最多水的容器的更多相关文章

  1. [LeetCode] Container With Most Water 装最多水的容器

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...

  2. LeetCode随缘刷题之盛最多水的容器

    package leetcode.day_01_30; /** * 给你 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点(i,ai) .在坐标内画 n 条垂直线,垂直线 i的两个端 ...

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

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

  4. [LeetCode] 11. Container With Most Water 装最多水的容器

    Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ...

  5. lintcode:装最多水的容器

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

  6. LeetCode 11. Container With Most Water (装最多水的容器)

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

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

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

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

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

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

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

随机推荐

  1. [Alpha阶段]第一次Scrum Meeting

    Scrum Meeting博客目录 [Alpha阶段]第一次Scrum Meeting 基本信息 名称 时间 地点 时长 第一次Scrum Meeting 19/04/01 大运村寝室6楼 40min ...

  2. 想要开发自己的PHP框架需要那些知识储备?

    作者:安正超链接:https://www.zhihu.com/question/26635323/answer/33812516来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  3. Java 创建一个简单的验证码图片

    代码如下: package lixin.gan.test; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2 ...

  4. Flask Session 使用和源码分析 —— (6)

    基本使用 from flask import Flask, session, redirect, url_for, escape, request app = Flask(__name__) @app ...

  5. 【翻译】asp.net core中使用MediatR

    这篇文章来自:https://ardalis.com/using-mediatr-in-aspnet-core-apps 本文作为翻译,有一些单词翻译成中文可能会有一些误解(对于读者)或者错误(对于作 ...

  6. 蒟蒻浅谈树链剖分之一——两个dfs操作

    树链剖分,顾名思义就是将树形的结构剖分成链,我们以此便于在链上操作 首先我们需要明白在树链剖分中的一些概念 重儿子:某节点所有儿子中子树最多的儿子 重链:有重儿子构成的链 dfs序:按重儿子优先遍历时 ...

  7. GC Tools

    GC Tools There are multiple ways to enable the GC log: specifying either of the flags -verbose:gc or ...

  8. [模板] 数学基础:快速幂/乘/逆元/exGCD/(ex)CRT/(ex)Lucas定理

    方便复制 快速乘/幂 时间复杂度 \(O(\log n)\). ll nmod; //快速乘 ll qmul(ll a,ll b){ ll l=a*(b>>hb)%nmod*(1ll< ...

  9. 雷军微博拧螺丝,CFO为粉丝数发愁

    导读 小米集团联合创始人.品牌战略官黎万强4年前写的书<参与感>,估计又要热卖了. 3月24日,小米CFO周受资发微博,“我刚接受了同事的挑战,要在一定时间内在微博上有更多的粉丝”,并向粉 ...

  10. python基础----特性(property)、静态方法(staticmethod)、类方法(classmethod)、__str__的用法

    http://www.cnblogs.com/wangyongsong/p/6750454.html#_label0