博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【leetcode】Container With Most Water
阅读量:4327 次
发布时间:2019-06-06

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

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 class Solution { 2 public: 3     int maxArea(vector
& height) { 4 if(height.size()==0) return 0; 5 int n=height.size(); 6 int i=0; 7 int j=n-1; 8 int maxCapacity=0; 9 int tmp=0;10 11 while(i!=j)12 {13 14 if(height[i]<=height[j])15 {16 tmp=height[i]*(j-i);17 i++;18 }else if(height[j]<=height[i])19 {20 tmp=height[j]*(j-i);21 j--;22 }23 24 if(maxCapacity

 

转载于:https://www.cnblogs.com/jawiezhu/p/4469639.html

你可能感兴趣的文章
GridEh排序
查看>>
[oc学习笔记]多态
查看>>
Tomcat connectionTimeout问题定位处理
查看>>
【PP系列】SAP 取消报工后修改日期
查看>>
ZooKeeper学习第四期---构建ZooKeeper应用(转)
查看>>
JNday4-am
查看>>
UI控件(复习一下)
查看>>
window下自己主动备份数据库成dmp格式的bat写法
查看>>
Memcache存储大数据的问题
查看>>
HDU 5050 Divided Land(进制转换)
查看>>
python进阶学习笔记(三)
查看>>
javascript语法之Date对象与小案例
查看>>
Day45 jquery表格操作、轮播图
查看>>
POJ 2079 Triangle 旋转卡壳求最大三角形
查看>>
【模板】树链剖分
查看>>
计算机博弈研究——六子棋
查看>>
在Visualforce page中用自带的控件实现Ajax回调后台方法(并且可以用js去动态给parameters赋值)...
查看>>
Android驱动开发第七章
查看>>
ISO 9141-2 and ISO 14230-2 INITIALIZATION and DATA TRANSFER
查看>>
特征点检测--基于CNN:TILDE: A Temporally Invariant Learned DEtector
查看>>