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. ubuntu 16.04 编译安装 trl8291cu系列 无线网卡驱动

    1 先 下载git包 和相关编译工具 sudo apt-get update sudo apt-get install git linux-headers-generic build-essentia ...

  2. python基础11_函数作用域_global_递归

    看到了一个16进制转换的小知识点,就验证了一下运行结果. #!/usr/bin/env python # coding:utf-8 # 看到了16进制转换的问题.顺便验证一下. a = 255 b = ...

  3. GOPATH

    环境变量 GOPATH 的值可以是一个目录的路径,也可以包含多个目录路径,每个目录都代表 Go 语言的一个工作区(workspace).这些工作区用于放置 Go 语言的源码文件(source file ...

  4. python+flask开发小白第二天

    使用VSCode编译python web页面 1.先从最基础的说起吧,关于VSCode的使用: 运行python程序与运行java,c,c++程序一样,需要新建一个文件,第一个文件建议不要新建在本地的 ...

  5. Python全栈之路----函数进阶----生成器

    生成器特点: 不能立即产生,取一次创建一次 只能往前走 等到走到最后,就会报错 >>> a = [i for i in range(1000)] >>> a [0, ...

  6. jq实时监测输入框内容改变

    $(document) .on('input propertychange','#telInput',function (e) { if (e.type === "input" | ...

  7. 创建java类并实例化类对象

    创建java类并实例化类对象例一1.面向对象的编程关注于类的设计2.设计类实际上就是设计类的成员3.基本的类的成员,属性(成员变量)&方法 面向对象思想的落地法则一:1.设计类,并设计类的成员 ...

  8. s2第六章继承和多态

    public class Employee { //年龄 public int Age { get; set; } //性别 public Gender Gender { get; set; } // ...

  9. 第2章 Java基本语法(下): 流程控制--项目(记账本)

    2-5 程序流程控制 2-5-1 顺序结构 2-5-2 分支语句1:if-else结构 案例 class IfTest1{ public static void main(String[] args) ...

  10. LDAP解决多个服务器多个samba,不能指定多个samba域 的问题

    问题:在创建账号的时候,必须指定一个sambaDomain,但是只能指定一个,但是我有多个samba域要集成,那怎么办呢,怎么弄都只能登陆一个samba,不能所有的都登,经过反复的测试,反复的测试,找 ...