leetcode 11. Container With Most Water
2016-02-23 14:00
411 查看
题意
求任意两条线段之间围成的面积最大值。题解
(左右线段高度不一样时取小的,面积为:min(height[left], height[right]) * (right - left);
代码
class Solution { public: int maxArea(vector<int>& height) { int left = 0; int right = height.size() - 1; int maxarea = 0; while(left < right) { int nowarea = min(height[left], height[right]) * (right - left); maxarea = max(nowarea, maxarea); if(height[left] < height[right]) left++; else right--; } return maxarea; } };
相关文章推荐
- UVALive 4725 Airport 贪心 二分 模拟
- Dispatcher initialization failed
- AIM Tech Round (Div. 1) C. Electric Charges 二分
- salt服务端向客户端同步grains错误一枚
- Submission Details
- http://blog.csdn.net/limingchuan123456789/article/details/16849897
- 'hibernate.dialect' must be set when no Connection available
- 24-题目1436:Repair the Wall
- Paint类
- Jenkins进阶系列之——02email-ext邮件通知模板
- 关于 “does not contain bitcode.”的错误解决办法
- WindowsAPI - Net - WSAStartup - Baidu.com
- process launch failed: Security
- tools:context=".MainActivity的作用
- poj2010 Moo University - Financial Aid
- VS2008启动时提示“Package load failure”
- waiting for X server to shut down Server terminated successfully(0) ,closing log file
- AIDL service纪事 注意事项
- 人工智能 有限状态机 的时代过去了
- could not obtain the localhost address