首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >LeetCode 11. 盛最多水的容器

LeetCode 11. 盛最多水的容器

作者头像
编程之心
发布于 2020-08-12 16:05:16
发布于 2020-08-12 16:05:16
4280
举报
文章被收录于专栏:编程之禅编程之禅

A

11. 盛最多水的容器

代码语言:javascript
复制
/**
 * [11. 盛最多水的容器](https://leetcode-cn.com/problems/container-with-most-water/)
 * 一个非负数组。寻找两个坐标,能构成最大面积水池。
 * 输入:[1,8,6,2,5,4,8,3,7] 
 * 输出:49
 * 方法1:双遍历,x从0开始,y从x+1开始,求面积 (y - x) * height_diff。O(n^2^)
 * 方法2:两边夹逼,取高度低的那个往里挪。O(n)
 */
class Solution {
    public int maxArea(int[] a) {
        int max = 0;
        for (int i = 0, j = a.length - 1; i < j; ) {
            int minH = a[i] < a[j] ? a[i++] : a[j--];
            max = Math.max(max, (j - i + 1) * minH);
        }
        return max;
    }
}

R

https://frenxi.com/http-headers-you-dont-expect/

最酷的互联网公司现在把招聘信息放在了HTTP请求头x-recruiting里面

T

《数据结构与算法之美》笔记

S

新版IntelliJ IDEA的更新

https://blog.csdn.net/weixin_43413658/article/details/105839472

微信定时提醒应用

https://blog.betacat.io/post/how-wecron-schedules/

LeetCode前300题

https://leetcode.wang/

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/05/31 ,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • A
  • R
  • T
  • S
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档