LeetCode_Container With Most Water
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的更多相关文章
- [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 ...
- [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 ...
- [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 ...
- [LeetCode] Trapping Rain Water 收集雨水
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- [LeetCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- 如何装最多的水? — leetcode 11. Container With Most Water
炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...
- 【leetcode】Container With Most Water
题目描述: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...
- [LintCode] Trapping Rain Water 收集雨水
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- [LintCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
随机推荐
- CCI_chapter 16 Low level
16.5 Write a program to find whether a machine is big endian or little endian Big-Endian和Little-Endi ...
- windows下查看端口占用情况
最近在用ICE做分布式应用 https://doc.zeroc.com/pages/viewpage.action?pageId=5048454 写了一个client 和server.server监听 ...
- redis maxmemory设置
关于maxmemory的设置,如果redis的应用场景是作为db使用,那不要设置这个选项,因为db是不能容忍丢失数据的. 如果作为cache使用,则可以启用这个选项(其实既然有淘汰策略,那就是cach ...
- 2015第24周二Spring事务2
今天继续深入学习SPring事务,发现网上很多文章都是很相似的转载没多少价值,就觉得更有必要把这个主题深入下去,先是摘录那些对自己有用的观点,后期再结合源码进行全面的整理. Spring提供了许多内置 ...
- Hello Bolg!
初来乍到,将就闹点小情绪吧 博客, 作为一个即将毕业的小码农, 第一次写这东西似乎生涩了点. 而且第一眼看到这东西还觉得特玄乎,不过“化抽象为具体, 化复杂为简单”不正是自己的职业操守吗. 于是, 我 ...
- 使用kthread内核线程的内核模块
这里使用了msleep(50); printk 开启其实挺大的,当我使用msleep(10);机器直接卡死了: 另外ISERR不能判断结构体的,只能判断 空指针 #cat hello.c #inclu ...
- eclipse指定启动时的jdk(xjl456852原创)
在eclipse安装目录中找到eclipse.ini 在第一行配置(即可启动按指定版本的jdk启动eclipse): -vm D:\soft\Java\jre8\bin\server\jvm.dll ...
- Counting Squares_hdu_1264(矩阵).java
Counting Squares Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 生命周期-初识IOS
经常因为生命周期的事情,而视图顺序加载错误,或者出现一系列的小错误并且修改不出来,程序员不知道生命周期确实挺可悲的. IOS生命周期: 自上而下的执行,并且viewDidLoad只会执行一次,所以我们 ...
- MongoDB 和 mySql 的关系
1. mysql 和 MongoDb MySQL与MongoDB都是开源的常用数据库,但是MySQL是传统的关系型数据库,MongoDB则是非关系型数据库,也叫文档型数据库,是一种NoSQL的数据库. ...