leetcode11
public class Solution
{
//public int MaxArea(int[] height)
//{
// var max = 0;
// for (int i = 0; i < height.Length; i++)
// {
// for (int j = 0; j < height.Length; j++)
// {
// if (i == j)
// {
// continue;
// }
// var min = Math.Min(height[i], height[j]);
// var dif = Math.Abs(i - j);
// var product = min * dif;
// max = Math.Max(max, product);
// }
// }
// return max;
//}
public int MaxArea(int[] height)
{
int max = int.MinValue;
for (int i = , j = height.Length - ; i < j;)
{
if (height[i] > height[j])
{
max = Math.Max(max, height[j] * (j - i));
j--;
}
else
{
max = Math.Max(max, height[i] * (j - i));
i++;
}
}
return max;
}
}
下面这个解决方案算是一种搞笑吧,夸张的6796ms,居然也能AC!
class Solution:
def findTopTwoNum(self,height):
top1 = -1
top1_index = -1 top2 = -1
top2_index = -1
for i in range(len(height)):
if top1 < height[i]:
top1 = height[i]
top1_index = i for i in range(len(height)):
if i != top1_index and top2 < height[i]:
top2 = height[i]
top2_index = i return top1_index,top2_index def maxArea(self, height: 'List[int]') -> 'int':
#在height中找最大的两个数字,以及这两个数字的坐标
left,right = self.findTopTwoNum(height) ma = min(left,right) * (right - left)
for i in range(left,-1,-1):
for j in range(right,len(height)):
area = min(height[i],height[j]) * (j-i)
if area > ma :
ma = area
return ma
leetcode11的更多相关文章
- [array] leetCode-11. Container With Most Water-Medium
leetCode-11. Container With Most Water-Medium descrition Given n non-negative integers a1, a2, ..., ...
- LeetCode11 Container With Most Water
题意: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...
- LeetCode-11. 盛最多水的容器
给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...
- [Swift]LeetCode11. 盛最多水的容器 | Container With Most Water
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ...
- Leetcode11 Container With Most Water 解题思路 (Python)
今天开始第一天记录刷题,本人编程小白,如果有写的不对.或者能更完善的地方请个位批评指正! 准备按tag刷,第一个tag是array: 这个是array的第一道题:11. Container With ...
- LeetCode11:Container With Most Water
public int MaxArea(int[] height) { ; ; ; while(start<end) { max=Math.Max(max,Math.Min(height[star ...
- LeetCode11.盛最多水的容器
给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...
- 思维题(两点逼近)LeetCode11 Container with Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- LeetCode11.盛最多水的容器 JavaScript
给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...
随机推荐
- IntelliJ IDEA 如何生成时序图?
进入扩展程序安装 File > Settings > Plugins > Browse Repositories 搜索 SequenceDiagram,点击右边 Install 安装 ...
- svn同步小脚本
企业中难免会有使用svn 的怎么给svn做好备份呢 下面是用两个脚本进行同步和监控 同步脚本: #!/bin/bash i=1 while true do if [ $(expr $i % 12) = ...
- jQuery-1.样式篇
jQuery对象与DOM对象 对于才开始接触jQuery库的初学者,我们需要清楚认识一点: jQuery对象与DOM对象是不一样的 可能一时半会分不清楚哪些是jQuery对象,哪些是DOM对象,下面重 ...
- jQuery ajax瀑布流加载静态的列表页面
1.加载一行数据 <script> //滚动加载事件 var Loadurl = "{$url}"; if(window.location.href !== Loadu ...
- Codeforces1062A. A Prank(暴力)
题目链接:传送门 题目: A. A Prank time limit per test second memory limit per test megabytes input standard in ...
- Reading Level Assessment Using Support Vector Machines and Statistical Language Models-paper
Authors: Sarah E. Schwarm University of Washington, Seattle, WAMari Ostendorf University of Washingt ...
- 创建java类并实例化类对象
创建java类并实例化类对象例一1.面向对象的编程关注于类的设计2.设计类实际上就是设计类的成员3.基本的类的成员,属性(成员变量)&方法 面向对象思想的落地法则一:1.设计类,并设计类的成员 ...
- Spring Boot 非常好的学习资料
from@https://gitee.com/didispace/SpringBoot-Learning Spring Boot 2.0 新特性学习 简介与概览 Spring Boot 2.0 正式发 ...
- 转载:python list和set的性能比较+两者转换
两者性能比较(转自http://www.linuxidc.com/Linux/2012-07/66404.htm) 本来是知道在Python中使用Set是比较高效,但是没想到竟然有这么大的差距: ~$ ...
- 记一次php脚本memory exhausted
表象报错如下: Error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 16651985 bytes) 出 ...