首页 > 其他分享 >11. Container With Most Water

11. Container With Most Water

时间:2022-11-01 14:15:08浏览次数:53  
标签:11 container int maxS Water Most thisS Container ai

Given n non-negative integers a1a2, ..., an, where each represents a point at coordinate (iai). n vertical lines are drawn such that the two endpoints of line i is at (iai) 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 and n is at least 2.

 

class Solution {     public int maxArea(int[] a) {        int i = 0;        int j = a.length - 1;        int maxS = 0;        int thisS = 0;        while (i != j) {             thisS = (j - i) * Math.min(a[i], a[j]); //面积等于底*高            maxS = thisS > maxS ? thisS : maxS;            if (a[i] > a[j]) //寻找有无更高的柱子               j--;           else                i++;        }                return maxS;     } }

标签:11,container,int,maxS,Water,Most,thisS,Container,ai
From: https://www.cnblogs.com/MarkLeeBYR/p/16847461.html

相关文章

  • leetcode111-二叉树的最小深度
    111.二叉树的最小深度 这道题相比 104.二叉树的最大深度 还是难上一些的,但也不算太难。BFS/***Definitionforabinarytreenode.*structTreeNode{......
  • 邀您一起见证11位女性编码艺术家和艺术编码家生成绽放
     是以NFT为中心的的区块链线上交易所,始创把NFT做到全网全链。Chamcha交易所里面用户可以通过相对比较简单的方式入门NFT,包括用信用卡或USDC稳定币就可以购买NFT。  ......
  • 2022-11-01
    棕榈:2D:下跌  2H:上涨  20F:上涨第一波 总结:2D下跌,2H上涨第二波,20F上涨第一波。做空等2F第二波结束等20F上涨第二波顶背驰 ......
  • docker-compose报错Traceback (most recent call last) 运行命令很慢
    [root@szweb32yml]#./docker-compose-vTraceback(mostrecentcalllast):File"docker-compose",line2,in<module>File"<frozenimportlib._bootstrap>",li......
  • c++11新增容器 array
    array中数据存于栈中 ......
  • web11 路由
    //express中,路由指客户端请求与服务器处理函数的映射关系//express中,路由分三部分,请求类型,请求url,处理函数//METHOD指请求类型//path是url//HANDLER是处理函数/......
  • 当前SAT主要关键技术及其相关文献2022-11-1
    摘录自:TasniemNasserAl-Yahya, MohamedElBachirMenai, HassanMathkour:Boosting the Performance of CDCL-Based SAT Solvers by Exploiting Backbon......
  • 【111】
    1662. 检查两个字符串数组是否相等 给你两个字符串数组 word1 和 word2 。如果两个数组表示的字符串相同,返回 true ;否则,返回 false 。数组表示......
  • 11月开展消防宣传答题活动
    11月开展消防宣传答题活动活动背景今年11月9日是第31个全国消防日,活动的主题是“抓消防安全,保高质量发展”。消防宣传活动中,各地区、各有关部门和单位要深刻领会关于......
  • KeyShot Pro 10.2 for Mac永久版(3D模型渲染软件)v10.2.113 中文版mac/win
    KeyShotPro10.1是一款功能强大的3D模型渲染软件,帮助你更好的创建3D渲染动画。其中KeyShot的GPU模式可用于实时渲染和本地渲染输出,一键访问GPU资源,从而利用多GPU性能扩展......