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的更多相关文章

  1. [array] leetCode-11. Container With Most Water-Medium

    leetCode-11. Container With Most Water-Medium descrition Given n non-negative integers a1, a2, ..., ...

  2. LeetCode11 Container With Most Water

    题意: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...

  3. LeetCode-11. 盛最多水的容器

    给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...

  4. [Swift]LeetCode11. 盛最多水的容器 | Container With Most Water

    Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ...

  5. Leetcode11 Container With Most Water 解题思路 (Python)

    今天开始第一天记录刷题,本人编程小白,如果有写的不对.或者能更完善的地方请个位批评指正! 准备按tag刷,第一个tag是array: 这个是array的第一道题:11. Container With ...

  6. LeetCode11:Container With Most Water

    public int MaxArea(int[] height) { ; ; ; while(start<end) { max=Math.Max(max,Math.Min(height[star ...

  7. LeetCode11.盛最多水的容器

    给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...

  8. 思维题(两点逼近)LeetCode11 Container with Most Water

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

  9. LeetCode11.盛最多水的容器 JavaScript

    给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...

随机推荐

  1. AndroidStudio连不上Android设备真机

    AndroidStudio连不上Android设备真机 刚好遇到这个问题,查阅了很多资料,看到有人分享了引起该问题的几个原因,我总结了一下: 1.手机设置问题.开USB调试 方法:手机设置-开发人员调 ...

  2. 类的构造器-init和new

    提到构造器,大家都会想到 __init__,那么__new__是什么?也是构造器. init 构造器 都很熟悉了,直接上代码 class MyClass(object): def __init__(s ...

  3. 基2时域抽取FFT、IFFT的C++实现代码,另附DFT与IDFT的原始实现--转1

    介绍网络上的原理介绍非常丰富,具体请自行搜索网络资源. 本算法依靠FFT流图进行布置. 算法 ##进行完所有的原理推导后,我们可以得到如下的16点FFT流图: 通过上图可以看出整个流图输入序列的顺序已 ...

  4. More is better

    题目描述: Mr Wang wants some boys to help him with a project. Because the project is rather complex, the ...

  5. 线性表seqList类及其父类list,模板类

    seqList模板类,线性表代码 # include "list.h" //代码清单2-2 顺序表类的定义和实现 // The Definition of seqList temp ...

  6. the principle of redbalck tree

  7. 一轮冲刺(NABCD)和需求分析

    N我们的创意是为了解决我们测量人员在测量结束后要计算一些数据的问题,当我们观测角度后,有大量的角度需要计算,有时会用到角度与弧度的转换. A我们测量人员知道计算的公式,了解一些c++和c# B我们这个 ...

  8. pytorch中,不同的kernel对不同的feature map进行卷积之后输出某一个channel对应的多个feature map如何得到一个channel的feature map

    实际上在卷积操作的时候,比如说,我某一层输出的feature map的size为4713*13 channel的数目为7,设经过某卷积层之后,网络输出的feature map的channel的数目为1 ...

  9. sql server中case when的用法

    Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END ...

  10. struts2 自定义异常拦截器配log4j

    log4j.rootLogger = debug,stdout,F log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.app ...