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.

  

class Solution {
public:
int maxArea(vector<int> &height) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int size = height.size();
if(size < ) return ;
int maxA = ,temp;
int left = , right = size -; while(left < right)
{
if( height[left] <height[right] )
{
temp = height[left] * (right - left);
left ++;
}else{ temp = height[right] * (right - left ) ;
right--;
} maxA = maxA > temp ? maxA : temp ; } return maxA ;
}
};

贪心的思想。

最近发现自己越来越搓了,要努力了!

LeetCode_Container With Most Water的更多相关文章

  1. [LeetCode] Pacific Atlantic Water Flow 太平洋大西洋水流

    Given an m x n matrix of non-negative integers representing the height of each unit cell in a contin ...

  2. [LeetCode] Trapping Rain Water II 收集雨水之二

    Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevati ...

  3. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  4. [LeetCode] Trapping Rain Water 收集雨水

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

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

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

  6. 如何装最多的水? — leetcode 11. Container With Most Water

    炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...

  7. 【leetcode】Container With Most Water

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

  8. [LintCode] Trapping Rain Water 收集雨水

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  9. [LintCode] Container With Most Water 装最多水的容器

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

随机推荐

  1. vim编辑器的设置文件

    vim配置特点: 1.按F5可以直接编译并执行C.C++.java代码以及执行shell脚本,按“F8”可进行C.C++代码的调试 2.自动插入文件头 ,新建C.C++源文件时自动插入表头:包括文件名 ...

  2. security

  3. 升级 pip版本

    安装第三方库:pip install Pillow 出现 You are using pip version 7.1.2, however version 9.0.1 is available. Yo ...

  4. [Qt] fontawesome图标

    fontawesome图标 fontawesome是一个图标的集合,里面有好多的图标,使用起来也还是非常方便的. 图标信息可以到官网去查:http://fontawesome.io/cheatshee ...

  5. jps命令使用

    jps工具 jps(Java Virtual Machine Process Status Tool)是JDK 1.5提供的一个显示当前全部java进程pid的命令,简单有用,很适合在linux/un ...

  6. Eclipse中Cannot find any provider supporting DES解决之道

    原文出处:http://blog.csdn.net/darwinchina/article/details/12037999 异常: Caused by: java.security.NoSuchAl ...

  7. python - socket练习(输入系统命令)

    socket_server端代码: #!/usr/bin/env python # -*- coding:utf-8 -*- # Auther: pangguoping import socket i ...

  8. GridControl 设置焦点单元格

    gdvNew.Focus(); //GridControl 控件获取焦点 gdvNew.FocusedRowHandle = _smtReport.Count - 1; //设置焦点行 gdvNew. ...

  9. Android SDK离线安装

    Android SDK离线安装是本文要介绍的内容,主要是来了解并学习Android SDK安装的内容,具体关于Android SDK是如何离线安装的内容来看本文详解. Android开发环境,完整的说 ...

  10. iOS_SN_深浅拷贝( 百度的)_转载

    文章原地址:http://www.cnblogs.com/5ishare/p/4362459.html 深浅拷贝前提是:是实现NSCopying或者NSMutableCopying协议. 浅拷贝只是复 ...