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

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

Container With Most Water

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.

Java代码:

public class Solution {    public int maxArea(int[] height) {        int j = height.length - 1, i = 0, ma = 0;		while (i < j) {			ma = Math.max(ma, (j - i) * (Math.min(height[i], height[j])));			if (height[i] < height[j]) {				i++;			} else if (height[i] >= height[j]) {				j--;			}		}		return ma;    }}
 

转载地址:http://tnuni.baihongyu.com/

你可能感兴趣的文章
UNITY自带的PACKAGE的UTILITY 里面有一个自带的FPS COUNTER
查看>>
AssetBundle Manager & Example Scenes
查看>>
fixed数据类型
查看>>
cg数据类型
查看>>
地图四叉树一般用在GIS中,在游戏寻路中2D游戏中一般用2维数组就够了
查看>>
Dijkstra算法(三)之 Java详解
查看>>
float4与half4数据类型
查看>>
安装Windows更新程序遇到错误:0x80070422
查看>>
Fresnel Reflection - 菲涅尔反射
查看>>
BRDF 光照模型
查看>>
unity编辑器的搜索框好特么坑啊,居然不支持*号通配符
查看>>
场景中,并没有灯源的存在,但是cube却会有灯光照射的反应,这就是Light Probe Group的作用。...
查看>>
unity3d 为什么要烘焙?烘焙作用是为了什么?
查看>>
[AR]高通Vuforia Getting Started
查看>>
Unity ios、android、pc一键打包(一)
查看>>
欧几里得空间
查看>>
今天写shader流光效果,shader代码少了个括号,unity shader compiler卡死且不提示原因...
查看>>
Unity shader saturate
查看>>
_LightColor0将会是主要的directional light的颜色。
查看>>
Unity的Shader如何控制投影颜色
查看>>