11. Container With Most Water
2016-03-21 10:53
393 查看
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.
Subscribe to see which companies asked this question
ij一头一尾 移动小的那个
..., 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.
Subscribe to see which companies asked this question
ij一头一尾 移动小的那个
public class Solution { public int min(int a,int b){ if(a>=b)return b; return a; } public int maxArea(int[] height) { int i = 0;int j= height.length-1;int max=0;int s; while(i<j){ s=(j-i)*min(height[i],height[j]); if(s>max)max=s; if(height[i]>height[j])j--;else i++; }return max; } }
相关文章推荐
- {typedir} {style} {tid} {aid} 分别是什么意思?
- 怪异的DetailsView控件的判断问题
- AIDL
- Profiler中WaitForTargetFPS详解
- Event Delivery: The Responder Chain
- Codeforces Round #345 (Div. 2) B. Beautiful Paintings
- lightoj 1236 - Pairs Forming LCM
- 两个重要的宏 offsetof 和 container_of
- BIO,NIO,AIO
- 成都某经济学院服务器raid卡损坏数据恢复成功
- TurboMail邮件系统再次通过涉密软件认证
- Deep Reinforcement Learning — Papers (2)
- Unable to obtain debug bridge
- 常用RAID简介及软RAID的实现
- UVA 514——Rails
- AIDL简介
- 严苛模式解决NetworkOnMainThreadException
- 英文歌曲:Right Here Waiting(此情可待)
- CF651B-Beautiful Paintings
- ABP源码分析七:Setting 以及 Mail