leetcode Container With Most Water
来源:互联网 发布:网络域名 编辑:程序博客网 时间:2024/06/05 06:05
找一个长乘以宽的最大情况,长就是纵坐标里的最小值,宽就是横坐标差
注意1:用O(n)时间复杂度,从两边一起往中间缩就行,因为他的长只和最短的短板有关,所以left++ , right--,可以画个图试试,因为如果要面积最大,那么left或者right往中间缩的时候,必须要大于他变化前的高度,否则不可能宽,长都减小,面积还能大。。。所以一次o(n)就可以了
class Solution {public: int maxArea(vector<int> &height) { int maxn = 0,left = 0,right = height.size() -1; while(left < right){ int tmp = (right - left)*min(height[left],height[right]); maxn = maxn >tmp?maxn:tmp; if(height[left] < height[right]){ left ++; } else right --; } return maxn; }};
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
- 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
- LeetCode:Container With Most Water
- 初识Linux
- Notification呼吸灯设置流程浅析
- weka apriori参数设置意义
- Swift等号误写成双等号,编译器不报错,运行报EXC_BAD错误
- Excel表快速转换成JSON字符串
- leetcode Container With Most Water
- 非Controller中调用Service
- Restore IP Addresses
- WebService--使用Axis2创建服务端和客户端
- WV.31-求串联电阻阻值
- 斑马打印机指令集
- 分子量(Molar Mass)
- 深入浅出设计模式 ------ Prototype(原型模式)
- Ansible模块知多少