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 <= ...
随机推荐
- ZOJ 3512 Financial Fraud (左偏树)
题意:给定一个序列,求另一个不递减序列,使得Abs(bi - ai) 和最小. 析:首先是在每个相同的区间中,中位数是最优的,然后由于要合并,和维护中位数,所以我们选用左偏树来维护,当然也可以用划分树 ...
- 滴滴Booster移动APP质量优化框架 学习之旅
推荐阅读: 滴滴Booster移动App质量优化框架-学习之旅 一 Android 模块Api化演练 不一样视角的Glide剖析(一) 一.Booster简介 Booster是滴滴最近开源一个的移动应 ...
- MVC用户验证
MVC提供了四种Filter(钩子),用于在Action执行之前或者之后,我们能够做一些事情,比如说判断有没有登录,比如说判断有没有权限. IAuthorizationFilter:在所有Filter ...
- Swoole 多协议 多端口 的应用
目录 概述 网络通信协议设计 多端口监听的使用 小结 概述 这是关于 Swoole 学习的第五篇文章:Swoole 多协议 多端口 的应用. 第四篇:Swoole HTTP 的应用 第三篇:Swool ...
- python3 Flask安装
虚拟环境 建议在开发环境和生产环境下都使用虚拟环境来管理项目的依赖. 为什么要使用虚拟环境?随着你的 Python 项目越来越多,你会发现不同的项目会需要 不同的版本的 Python 库.同一个 Py ...
- ue4 简单数据储存
- UE4 中的 C++ 编程介绍
https://docs.unrealengine.com/latest/CHN/Programming/Introduction/index.html UE4 中的 C++ 编程介绍 Unreal ...
- 洛谷P2905 [USACO08OPEN]农场危机Crisis on the Farm
P2905 [USACO08OPEN]农场危机Crisis on the Farm 题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每 ...
- 2014-9-13 NOIP模拟赛
NOIP2014模拟赛 ——lwher 题目名 环上的游戏 舞蹈课 数位和乘积 源文件 cycle.cpp/c/pas dancingLessons.pas/cpp digit.cpp.cpp/c/p ...
- 洛咕11月月赛部分题解 By cellur925
听说是你谷史上最水月赛?我不听我最菜 T1:终于结束的起点 月天歌名好评 给你一个模数 \(M\),请你求出最小的 \(n > 0\),使得\(fib(n)\) \(mod\) \(m=0\), ...