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. Java 获取class method parameter name

    package org.rx.util; import org.objectweb.asm.*; import java.io.IOException; import java.io.InputStr ...

  2. Java学习笔记34(sql基础 :增删改查1)

    create database qy97;/*创建数据库*/ use qy97; /*使用数据库 use 数据库名*/ show tables; /*查看所有的表*/ select database( ...

  3. Windows10 bypassUAC绕过用户账户控制

    使用这个github上的项目: https://github.com/L3cr0f/DccwBypassUAC 可以自行编译 全程UAC不介入,没反应. 测试: 权限提升真实有效

  4. Linux 查看端口被什么程序占用

    lsof -i:8899 输出: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEjava 38889 root 329u IPv6 5883661 ...

  5. 数据文件resize回收空间

    场景说明: 客户 ASM磁盘组,data磁盘组空闲空间90G,空间不足,因此强烈建议回收空间 空间回收方案: 1.数据文件resize,回收部分可用性空间(好处就是能够将ASM磁盘组free大小增加) ...

  6. 姿势估计实验-Realtime_Multi-Person_Pose_Estimation-CMU

    前言: 论文及源代码网址: https://github.com/ZheC/Realtime_Multi-Person_Pose_Estimation 地址2: https://github.com/ ...

  7. Python全栈之路----编程基本情况介绍

    1.多种编程语言的区别 (1)C\C++:学习成本高,学习周期长,偏系统底层,在开发硬件驱动.嵌入式.游戏引擎开发等领域有广泛应用. (2)JAVA:目前使用最广泛的编程语言,第一个跨平台运行的语言, ...

  8. N阶乘尾部的0个数

    N阶乘尾部的0个数 描述 设计一个算法,计算出n阶乘中尾部零的个数 思路: 1.1 * 2 * 3 * ... * n --> 1 * 2 * 3 * (2 * 2) * 5 * (2 * 3) ...

  9. 学习笔记TF043:TF.Learn 机器学习Estimator、DataFrame、监督器Monitors

    线性.逻辑回归.input_fn()建立简单两个特征列数据,用特证列API建立特征列.特征列传入LinearClassifier建立逻辑回归分类器,fit().evaluate()函数,get_var ...

  10. 学习笔记TF015:加载图像、图像格式、图像操作、颜色

    TensorFlow支持JPG.PNG图像格式,RGB.RGBA颜色空间.图像用与图像尺寸相同(height*width*chnanel)张量表示.通道表示为包含每个通道颜色数量标量秩1张量.图像所有 ...