[LeetCode]Container With Most Water, 解题报告
前言
题目
Note: You may not slant the container.
思路
http://www.processon.com,虽然很小众,但是确实很好用
AC代码
public class Solution {
public int maxArea(int[] height) {
int i, j, lh, rh, area, tmp, len = height.length;
lh = height[0];
rh = height[len - 1];
area = Math.min(height[0], height[len - 1]) * (len - 1);
for (i = 1, j = len - 2; i < j;) {
while (i < j && height[i] <= lh) {
i++;
}
if (i < j) {
lh = height[i];
}
while (j < j && height[j] <= rh) {
j--;
}
if (i < j) {
rh = height[j];
}
tmp = Math.min(lh, rh) * (j - i);
if (tmp > area) {
area = tmp;
}
}
return area;
}
}[LeetCode]Container With Most Water, 解题报告的更多相关文章
- LeetCode 2 Add Two Sum 解题报告
LeetCode 2 Add Two Sum 解题报告 LeetCode第二题 Add Two Sum 首先我们看题目要求: You are given two linked lists repres ...
- 【LeetCode】376. Wiggle Subsequence 解题报告(Python)
[LeetCode]376. Wiggle Subsequence 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.c ...
- 【LeetCode】649. Dota2 Senate 解题报告(Python)
[LeetCode]649. Dota2 Senate 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地 ...
- 【LeetCode】911. Online Election 解题报告(Python)
[LeetCode]911. Online Election 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ ...
- 【LeetCode】886. Possible Bipartition 解题报告(Python)
[LeetCode]886. Possible Bipartition 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu ...
- 【LeetCode】36. Valid Sudoku 解题报告(Python)
[LeetCode]36. Valid Sudoku 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址 ...
- 【LeetCode】870. Advantage Shuffle 解题报告(Python)
[LeetCode]870. Advantage Shuffle 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn ...
- 【LeetCode】593. Valid Square 解题报告(Python)
[LeetCode]593. Valid Square 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地 ...
- 【LeetCode】435. Non-overlapping Intervals 解题报告(Python)
[LeetCode]435. Non-overlapping Intervals 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemi ...
随机推荐
- My.Ioc 代码示例——注册项的注销和更新
当您需要从 Ioc 容器中注销/删除一个注册项的时候,您会怎么做呢? 有人曾经在 stackoverflow 上提问“如何从 Unity 中注销一个注册项”.对于这个问题,有人的回答是“有趣.你为什么 ...
- 从零开始学java(小游戏 石头剪刀布)
Game.java package com.java;import java.util.Scanner;public class Game { private Player player ...
- 解决java访问.netWebService的常见问题
到公司没多久,写了一个java调用.net写的webService结果期间用各种方法测试都没有完成,总是抛出异常,最后直接使用SOAP消息去进行调用才成功了,具体代码如下,仅供参考:import ja ...
- C文件函数总结
1.fopen(打开文件) 表头文件 #include<stdio.h> 定义函数 FILE *fopen(const char * path,const char * mode); pa ...
- jquery find选择器在不同浏览器下的差异
初步测试,5000个节点的隐藏. 代码如下: <!doctype html> <html lang="en"> <head> <scrip ...
- ejabberd,erlang,简单看了一下,总结一下,很肤浅
本来也没打算深入学习erlang,就是看一下他们的大概思路erlang每个自定义函数都能注册成进程,每个节点通过erl -name 'name@ip'.进去后,可以直接做远程调用,节点之间就靠一个连接 ...
- sql编程 1
declare emp_count number;begin select count(*) into emp_count from emp where HIOREDATE >= TO_DATE ...
- 感性体验 Android 5.0 Lollipop
引言 Android5.0大概是在11月下旬开始进行OTA推送,博主手上的这台五太子(Nexus 5)也在前几天收到了Google的推送,博主当然是按耐不住赶紧FQ升级啦,但无奈的是这个大版本更新包有 ...
- 2-16 HDO1106
这题寒假也没搞出来,但今天花了一小时终于搞定. 题意是输入一串数字字符,把‘5’当作空格,然后把被分割开的数字进行排序输出. 首先是字符串输入,按照高精度的处理方法,数值低位放到数组低位.(字符串型的 ...
- SAR-303 xml validator验证框架
// 配置文件详解 <mvc:annotation-driven validator="validator" /> <bean id="validato ...