LeetCode:Container With Most Water
来源:互联网 发布:美拍视频怎么上传淘宝 编辑:程序博客网 时间:2024/04/30 09:45
思路:假设最左边和最右边两根垂直线,它们和x轴形成一个桶,这个桶的面积就由直线之间的距离乘以它们中最低的高度,为了扩大桶的面积,必须放弃当前高度最低的桶,因为只要它存在,最低高度就不会变,而现在横向距离已经是最大,扩大距离是不可能的,所以,只能是舍弃最短高度的直线,左边最短,向右移动,右边最短,向左移动。
code:
class Solution {public: int maxArea(vector<int> &height) { int num = height.size(); if(num>1){ int front = 0,back = num-1; int ret = min(height[front],height[back])*(back - front); while(front<back){ if(height[front] < height[back]) front++; else back--; ret = max(ret,min(height[front],height[back])*(back - front)); } return ret; } return 0; }};
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
- android:singleLine="true" 是什么意思?
- 润肤日过输入负好高色而非
- XQuery内置函数
- 验证身份证有效性:
- 正则表达式 // 和##和~~
- LeetCode:Container With Most Water
- 找回密码,使用邮件发送方式
- require和require_once的区别
- SSDP
- Java 内部类
- 当几个引用指向同一个java对象的时候,用什么办法能让这几个引用都变成 null?
- LVM 在线扩容
- ios开发 - SWift初学笔记
- hello world