Array - Container With Most Water
/**
* 此为暴力解法
* Find two lines, which together with x-axis forms a container, such that the container contains the most water.
* @param height 高度
* @return 面积
*/
public int _maxArea(int[] height) {
int area = 0;
for(int i = 0; i < height.length; i++) {
for(int j = i+1; j < height.length; j++) {
int h = height[j] < height[i] ? height[j] : height[i];
area = area > (j-i)*(h) ? area : (j-i)*(h);
}
}
return area;
}
public int maxArea(int[] height) {
int area = 0;
// 两个指针
int i = 0;
int j = height.length-1;
while(i < j) {
int h = Math.min(height[i], height[j]);
area = Math.max(area, (j - i) * (h));
if(height[i] <= height[j]) {
i++;
} else {
j--;
}
}
return area;
}
Array - Container With Most Water的更多相关文章
- leetcode 11. Container With Most Water 、42. Trapping Rain Water 、238. Product of Array Except Self 、407. Trapping Rain Water II
11. Container With Most Water https://www.cnblogs.com/grandyang/p/4455109.html 用双指针向中间滑动,较小的高度就作为当前情 ...
- LeetCode Array Medium 11. Container With Most Water
Description Given n non-negative integers a1, a2, ..., an , where each represents a point at coordin ...
- LeetCode:Container With Most Water,Trapping Rain Water
Container With Most Water 题目链接 Given n non-negative integers a1, a2, ..., an, where each represents ...
- Leetcode11 Container With Most Water 解题思路 (Python)
今天开始第一天记录刷题,本人编程小白,如果有写的不对.或者能更完善的地方请个位批评指正! 准备按tag刷,第一个tag是array: 这个是array的第一道题:11. Container With ...
- leetcode-algorithms-11 Container With Most Water
leetcode-algorithms-11 Container With Most Water Given n non-negative integers a1, a2, ..., an , whe ...
- LeetCode解题报告—— Container With Most Water & 3Sum Closest & Letter Combinations of a Phone Number
1. Container With Most Water Given n non-negative integers a1, a2, ..., an, where each represents a ...
- Container With Most Water(LintCode)
Container With Most Water Given n non-negative integers a1, a2, ..., an, where each represents a poi ...
- Leetcode 11. Container With Most Water(逼近法)
11. Container With Most Water Medium Given n non-negative integers a1, a2, ..., an , where each repr ...
- 如何装最多的水? — leetcode 11. Container With Most Water
炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...
随机推荐
- Javascript 获取客户端的运营商 IP 地址 等
客户端获取运营商 会弹出安全隐患问题,需要修改IE activx 选项, 非常麻烦,用我的代码可以轻松获取. <script src="JS/jquery-1.4.1.js" ...
- HDU - 4704 sum 大数取余+欧拉降幂
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submi ...
- C++ - main()函数参数
main()函数及其参数说明 main()函数主要形式: int main(void) int main(int argc, char *argv[]) = int main(int argc, ch ...
- Mathematics Base - Tensor
以下是我对张量的理解,备注是具体解释,Xmind导出的图片没法显示出来,主要还是将张量间的关系画出来,方便理解. 图1 张量
- PowerDesigner设计表时显示注释列Comment,Columns中没有Comment的解决办法
我使用的PowerDesigner版本为16.5,如下图: 在所要编辑的表上双击,打开Table Properties窗口,并将上面的选项卡切换到Columns,如下图: 我们点击Customize ...
- 洛谷P3645 [APIO2015]雅加达的摩天楼(最短路+分块)
传送门 这最短路的建图怎么和网络流一样玄学…… 一个最朴素的想法是从每一个点向它能到达的所有点连边,边权为跳的次数,然后跑最短路(然而边数是$O(n^2)$除非自创复杂度比spfa和dijkstra还 ...
- Node.js 内置模块crypto加密模块(2) AES
AES:高级加密标准 ( Advanced Encryption Standard ) AES是一种对称加密算法:加密需要密钥,且加密密钥和解密密钥相同 下面是AES加密的Node实现: " ...
- axios发送两次请求原因及解决方法
axios发送两次请求原因及解决方法 最近Vue项目中使用axios组件,在页面交互中发现axios会发送两次请求,一种请求方式为OPTIONS,另外一种为自己设置的. 如图: 什么是CORS通信? ...
- 剑指Offer的学习笔记(C#篇)-- 连续子数组的最大和
题目描述 HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学.今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决.但是,如果向量 ...
- 用户角色权限查询添加bug集锦 用户密码加密 MD5 加盐 随机盐 spring的加密bcrypt
package cn.itcast.encode; import org.apache.commons.lang3.RandomStringUtils; import org.springframew ...