Container With Most Water
2016-02-29 20:46
330 查看
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.
Note: You may not slant the container.
class Solution { public: int maxArea(vector<int>& height) { int right = height.size() - 1; int left = 0; int ans = 0; while (left < right) { int area = (right - left) * min(height[right], height[left]); ans = max(ans, area); height[left] > height[right] ? --right : ++left; } return ans; } };
相关文章推荐
- wait3和wait4 Functions
- SSH连接时出现Host key verification failed的原因及解决方法
- Low-rank representation with local constraint for graph construction
- git push origin master出错:error: failed to push some refs to
- STL容器与拷贝构造函数 http://blog.csdn.net/heyutao007/article/details/6702626
- Train Problem II(卡特兰数+大数乘除)
- C++ vector 类学习笔记 http://blog.csdn.net/whz_zb/article/details/6827999
- ZOJ Paint the Grid Reloaded
- 【杭电oj】1702 - ACboy needs your help again!(栈和队列)
- HDU 1022 Train Problem I(stack)
- View、Canvas、Paint
- 详解Paint的setShader(Shader shader)
- aix5.3下安装svn命令
- PRVF-4661 During cluvfy on AIX platform
- 【分布式存储】GlusterFS failing to mount at boot with Ubuntu 14.04
- win10 Failed to open/create the internal network 'HostInterfaceNetworking-VirtualBox Host
- 11.2 Job Seperation causes WARNINGS and ORA-15025 ORA-27041 With Certain Users (文档 ID 1317692.1)
- 苹果手机safairi不支持position:fixed
- 车型识别“Hyper-class Augmented and Regularized Deep Learning for Fine-grained Image Classification”
- 【杭电】[1702]ACboy needs your help again!