leetcode刷题目 总结 记录 备忘11
来源:互联网 发布:捕鱼达人软件出售 编辑:程序博客网 时间:2024/06/05 00:24
leetcode11
Container With Most Water
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.
从两头开始 ,先求一次面积,两边下标差乘两者之间的最低值,即短板,之后开始遍历,数值小的一方往里走,因为是短板,所以得自己往里走,以期能找到一个让对面的数值成为小值的数,才有可能取得最大的面积,之后继续计算面积,与之前的面积相比,替换小的,完成遍历即可。原谅我的语言表述能力较弱。class Solution {public: int maxArea(vector<int>& height) { int l = 0, r = height.size() - 1; int max = 0; while (l < r) { int temp = (r-l) * min(height[l], height[r]); if (temp > max) max = temp; if (height[l] <= height[r]) l++; else r--; } return max; }};
0 0
- leetcode刷题目 总结 记录 备忘11
- leetcode 刷题目,总结,记录,备忘 13
- leetcode刷题目 ,总结,记录,备忘206
- leetcode 总结,记录,备忘。153
- leetcode刷题。总结,记录,备忘 104
- leetcode刷题。总结,记录,备忘 100
- leetcode刷题。总结,记录,备忘 191
- leetcode刷题。总结,记录,备忘。168
- leetcode刷题, 总结,记录,备忘 171
- leetcode刷题 ,总结,记录,备忘。144
- leetcode刷题,总结,记录, 备忘 141
- leetcode刷题,总结,记录,备忘。116
- leetcode刷题,总结,记录,备忘。96
- leetcode刷题。记录,总结,备忘。217
- leetcode 刷题, 总结,记录,备忘 35
- leetcode刷题,总结,记录,备忘 226
- leetcode刷题,总结,记录,备忘 169
- leetcode刷题,总结,记录,备忘137
- poj 3691 AC自动机+dp(修复DNA使其不带病毒)
- u3d脚本编写
- HDU1114 动态规划
- 我的C语言入门到精通之路 day02
- Intent(有无返回值得跳转)
- leetcode刷题目 总结 记录 备忘11
- Spreadsheet Tracking
- UIView
- C与C++的区别与相互调用
- js数组操作:
- 博客开篇
- 控件布局——RelativeLayout(上)
- HDU - 1010 Tempter of the Bone 深搜模板题(DFS)解题报告
- UI的类--UIView