博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Leetcode] Container with Most Water
阅读量:4670 次
发布时间:2019-06-09

本文共 684 字,大约阅读时间需要 2 分钟。

Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.

Note: You may not slant the container.

 

  1. left pointer

  2. right pointer

  3. max to store the result

 

edge case

height == null?

height.length == 0?

time complexity O(n)

 

public int maxArea(int[] height){        if(height == null || height.length == 0) return 0;        int left = 0, right = height.length-1;        int max = 0;        while(left

 

转载于:https://www.cnblogs.com/momoco/p/4849065.html

你可能感兴趣的文章
巴洛克式和哥特式的区别
查看>>
[转载]:C# 中结构与类的区别
查看>>
maven-javadoc-plugin
查看>>
Ubuntu 14.04环境变量修改
查看>>
多线程Lock版生产者和消费者模式
查看>>
zoj3802:easy 2048 again(状压dp)
查看>>
Jenkins 自动化集成之路 Linux 安装 maven
查看>>
vue 自学笔记(七) 组件细节问题
查看>>
CSUOJ 1856 Sokoban 模拟
查看>>
List实体去重
查看>>
python函数回顾:abs()
查看>>
初识大数据(四. 大数据与人工智能的关系)
查看>>
netty 入门(一)
查看>>
Intellij Idea 15 下新建 Hibernate 项目以及如何添加配置
查看>>
《火星!火星!》
查看>>
大道至简读书笔记一
查看>>
php apache 配置后不能正常显示html文件的解决方法
查看>>
FILE类型指针的头文件
查看>>
牛客网暑期ACM多校训练营(第五场)J-plan (模拟)
查看>>
如何做一个跨平台的游戏App?
查看>>