Leetcode在线编程container-with-most-water
来源:互联网 发布:ibm电池修复软件 编辑:程序博客网 时间:2024/06/06 00:08
Leetcode在线编程 container-with-most-water
题目链接
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.
题意
x轴正方向上,有长度不等的垂直于X轴的线段,现找出与X轴围起来面积最大的那对线段。
解题思路
2条线段与x轴围起来的面积,决定因素是短的那条
先取头尾两条线段i,j
如果h[i]
AC代码
class Solution {public: int maxArea(vector<int> &height) { int i = 0 , j = height.size()-1; int Max = 0; while(i<j) { int tmp; if(height[i] < height[j]) { tmp = (j-i)*height[i]; i++; } else { tmp = (j-i)*height[j]; j--; } Max = max(Max,tmp); } return 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
- Swift实战
- Logstash5.0 手动安装插件
- JAVA中Collections代码详解
- 【Codeforces Round #384 (Div.2)】(A,B,C)
- Unity5 AssetBundle 打包以及加载
- Leetcode在线编程container-with-most-water
- swift语言的学习笔记十(block)
- Facebook Surround360 学习笔记--(2)算法原理
- 类中的成员属性和成员方法
- ffmpeg.exe移植到vs2010编译步奏
- swift语言的学习笔记十一(performSelector)
- swift语言的学习笔记十二(willSet与didSet)
- ansj分词方式详细解析
- 在 Linux 上如何清除内存的 Cache、Buffer 和交换空间