LeetCode 11. Container With Most Water
来源:互联网 发布:国际数据流量怎么开通 编辑:程序博客网 时间:2024/06/05 03:24
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 and n is at least 2.
找两根线
直接遍历是
class Solution {public: int maxArea(vector<int>& height) { int len = height.size(); vector<int>::iterator iter; int a[len],i,j,temp,ans=0; for(i=0,iter=height.begin();iter!=height.end();i++,iter++){ a[i]=*iter; } i=0;j=len-1; while(i<j){ temp=(a[i]<a[j]?a[i]:a[j])*(j-i); ans=ans>temp?ans:temp; if(a[i]>a[j]) j--; else i++; } return ans; }};
阅读全文
0 0
- LeetCode 11. Container With Most Water
- [LeetCode]11.Container With Most Water
- LeetCode --- 11. Container With Most Water
- LeetCode 11.Container With Most Water
- [Leetcode] 11. Container With Most Water
- [leetcode] 11.Container With Most Water
- 【leetcode】11. Container With Most Water
- [LeetCode]11. Container With Most Water
- 11. Container With Most Water LeetCode
- leetcode 11. Container With Most Water
- leetcode 11.Container With Most Water
- [LeetCode OJ]11. Container With Most Water
- [leetcode] 11. Container With Most Water
- Leetcode 11. Container With Most Water
- leetcode 11.Container With Most Water
- leetcode 11. Container With Most Water
- LeetCode 11. Container With Most Water
- LeetCode *** 11. Container With Most Water
- HDU1098 规律题
- 嵌入式 Linux 对内存的直接读写(devmem)
- pat 乙级 1060. 爱丁顿数(25)
- 传统MVC和rest服务调用的区别
- webpack总结
- LeetCode 11. Container With Most Water
- leetcode Add Two Numbers
- Lock的使用
- Java 8 操作流
- 170909_Spring英文文档阅读(五)_2.2 Web_spring-web
- 51nod 1405 树的距离之和 (树形dp)
- Java API 与HBase交互实例 (总结11)
- HTTP(1)之持久链接(关键词:HTTP/持久链接/keep-alive/HTTP persistent connection/HTTP keep-alive/HTTP connection)
- UVALive