[leetcode题后感]container with most water
来源:互联网 发布:怎么开淘宝网店要钱吗 编辑:程序博客网 时间:2024/05/18 03:01
此题tag 为 two pointer
而two pointer的经典应用是2sum ksum类似的题目
本题一开始并没有很好的思路 因为首先题目标书也不是很明确,应该注意两条垂直的直线之间的water量不用考虑其他直线的情况,
即 water的量就等于两条直线与x轴所构成的容器的容量
本题比较难想,不知道如何转换为常用的算法 经搜索发现了最大container的两条性质
即最大container的左边i 右边j 不存在i左边有比i的高度更高的直线 不存在j的右边比j的高度更高的直线
有了以上两条性质,还是不是很懂如何应用到算法当中
其实这两条性质装换为算法 就是说
当i和j逐步向中间靠拢并且找到了最大的area时,可以放心的进行靠拢而不用考虑i'<i,j'>j使得area<i',j'> 大于 area<i,j>的情况
所以 至此可以考虑用两个指针初始化为0和n-1,选择i和j中最矮的一个进行++或-- 然后依次计算area的值找到max
0 0
- [leetcode题后感]container with most water
- LeetCode: Container With Most Water
- [LeetCode]Container With Most Water
- LeetCode Container With Most Water
- LeetCode: Container With Most Water
- [Leetcode] Container With Most Water
- Leetcode: Container With Most Water
- [LeetCode] Container With Most Water
- LeetCode Container With Most Water
- [Leetcode] Container With Most Water
- [LeetCode]Container With Most Water
- LeetCode-Container With Most Water
- Container With Most Water leetcode
- LeetCode - Container With Most Water
- LeetCode: Container With Most Water
- Leetcode: Container With Most Water
- 【LeetCode】Container With Most Water
- Leetcode: Container With Most Water
- 学生管理系统
- iOS打电话功能
- hibernate:XXX is not mapped问题的解决
- 使用STL来模拟Treap的功能
- MySQL版本号含义
- [leetcode题后感]container with most water
- IOS开发语言Swift入门连载---基本运算符
- everything start from keystone(4)
- 博弈(部分)
- myeclipse 使用maven出现的问题
- linux下的C\C++多进程多线程编程简易例子
- java设计模式
- 个人经历
- 【索引】Dynamic Programming