Container with most water
2015-08-11 17:14
363 查看
题目比较简单,每次找较小的板往里移,得到的容器的容积最大的就是所求的容积
public class Solution { public static int maxArea(int[] height) { int begin = 0, high, end = height.length - 1; int max = 0; while (end >= begin) { high = height[begin] < height[end] ? height[begin] : height[end]; max = high * (end - begin) > max ? high * (end - begin) : max; if (height[begin] < height[end]) begin++; else end--; } return max; } }
相关文章推荐
- main函数中通过使用Person类和AddressBook类,创建对象、调用方法,实现以下8个功能
- Ubuntu下编译运行Kamailio
- AIX开启telnet服务
- POJ 3068 "Shortest" pair of paths(最小费用最大流-mcmf)
- Webmin version 1.760 is now available, but you are running version 1.730.
- 2015 HUAS Summer Trainning #5~A
- Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE的报错的解决方法
- Leetcode -- Container With Most Water
- Leetcode#11||Container With Most Water
- 172 Factorial Trailing Zeroes
- HDU 1532 Drainage Ditches
- SmtpClient发邮件时为什么用MailMessage.From而不用MailMessage.Sender
- MDK __main过程分析
- 树形DP - hdu5293 Tree chain problem
- HDU - 4630 No Pain No Game (线段树 + 离线处理)
- Binder与AIDL服务
- **深入浅出的事件路由(view hit test)**
- leetCode #217 Contains Duplicate
- HDU 4819 Mosaic D区段树
- sleep和wait区别