LeetCode 11. Container With Most Water

Solution1:
参考网址:http://www.cnblogs.com/grandyang/p/4455109.html
定义两个指针向中间走,贪心啊。。

class Solution {//
public:int maxArea(vector<int>& height) {int water = 0;int i = 0, j = height.size() - 1;while (i < j) {int h = min(height[i], height[j]);water = max(water, (j - i) * h);while (height[i] <= h && i < j) i++;while (height[j] <= h && i < j) j--;}return water;}
};

【贪心+双指针】LeetCode 11. Container With Most Water相关推荐

  1. [贪心|双指针] leetcode 11 盛最多水的容器

    [贪心|双指针] leetcode 11 盛最多水的容器 1.题目 题目链接 给你 n 个非负整数 a1,a2,-,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 ...

  2. LeetCode 11 Container With Most Water

    问题:给出一个数组nums,要求选择2个,使得容器中包含的水最多. 思路:假设选取x,y,其中x<y,则包含的水为min(x,y)*(index(y) - index(x)).此时应该选择在最小 ...

  3. LeetCode 11.Container With Most Water

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

  4. leetcode 11. Container With Most Water

    题意:题目大概意思就是让你找两个数使得两个数的最小值乘以他们的距离最大Area 题解:设置两个变量, 一个是从头开始,一个是从尾开始,计算两个数的Area,并更新最大值,如果开始的元素大于结尾的元素则 ...

  5. LeetCode 11. Container With Most Water--Java 解法--困雨水简单版

    LeetCode 11. Container With Most Water–Java 解法 此文首发于我的个人博客:LeetCode 11. Container With Most Water–Ja ...

  6. 【LeetCode】11. Container With Most Water 解题小结

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

  7. leetcode -eleven:Container With Most Water

    2019独角兽企业重金招聘Python工程师标准>>> Given n non-negative integers a1, a2, ..., an, where each repre ...

  8. 11. Container With Most Water

    2019独角兽企业重金招聘Python工程师标准>>> 就是说,x轴上在1,2,...,n点上有许多垂直的线段,长度依次是a1, a2, ..., an.找出两条线段,使他们和x抽围 ...

  9. [贪心|字符串] leetcode 3 无重复字符的最长子串

    [贪心|字符串] leetcode 3 无重复字符的最长子串 1.题目 题目链接 给定一个字符串,请你找出其中不含有重复字符的最长子串的长度. 示例1: 输入: "abcabcbb" ...

最新文章

  1. 自然语言处理笔记4-哈工大 关毅
  2. 【SpringBoot】查看运行环境中所有的spring bean
  3. 亲儿子 | Azure SignalR 服务现在支持 ASP.NET
  4. 反质数问题,求不大于n的最大反质数
  5. python 把txt变成字符串_如何通过 Python 如何写文件 ?
  6. vue+nodejs 将canvas发布到dlna投屏服务
  7. Proxmark3 easy gui 5.13 版本 编译日期2019-4-17 冰人4月份最新固件
  8. Mac系统安装Windows系统
  9. vmware vsphere出现“需要整合虚拟机磁盘”的告警处理方法(完整版)
  10. DEVC6.0使用教程
  11. 域网批量装系统通用版服务器,局域网批量网刻Ghost
  12. css3实现方框里打钩样式
  13. 许远东受邀上海管理科技论坛做《LTD数字化经营方法论》分享
  14. Python图形用户界面和游戏开发
  15. vue 使用高德地图 api
  16. linux 内核模块 编写例子,LINUX内核模块编程8
  17. 2021年HECTF部分Writeup
  18. 计算机组成原理17----CPU指令流水线
  19. Urlrewrite(url地址重写)和UrlRewriteFilter
  20. TikTok || 一个正在冉冉上升的海外网红KOL营销市场

热门文章

  1. 【学习笔记】卡尔曼滤波中的协方差矩阵
  2. java反射获取注解id,通过反射获取注解(Annotation)
  3. jmeter web监听结果_监听器-聚合报告监听性能测试结果
  4. c语言中什么函数可以作为虚函数,C++语言中的“虚函数”就像C语言中的指针,必须要弄懂的...
  5. (02)vtk 绘制模型的外轮廓线 模型轮廓线
  6. odbc数据库access丢失_有关使用access数据库,odbc中碰到的一些问题。
  7. python dll 调用 方法未找到_大牛经验分享之谈:Python调用.NET库的方法步骤(建议收藏)...
  8. wordpress直接处理$_post_实战:Drupal迁移到WordPress
  9. 二进制安装mysql集群_实战mysql集群搭建(一)--centos7下二进制安装mysql-5.6
  10. wpf messagebox.show()点击其他地方会闪烁_定时、童锁、故障查询,线控器上的这些功能你会用吗?...