Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, a ...
題目描述 給定 n 個非負整數 a ,a ,...,an,每個數代表坐標中的一個點 i,ai 。畫 n 條垂直線,使得垂直線 i的兩個端點分別為 i,ai 和 i, 。找出其中的兩條線,使得它們與x軸共同構成的容器可以容納最多的水。 注意:你不能傾斜容器,n 至少是 。 解題思路 考慮用雙指針法解題。維護兩個指針f l分別指向數組左右兩端,則f和l構成的容器盛水體積計算公式為min height ...
2018-05-15 22:31 0 1320 推薦指數:
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, a ...
炎炎夏日,還是呆在空調房里切切題吧。 Container With Most Water,題意其實有點噱頭,簡化下就是,給一個數組,恩,就叫 height 吧,從中任選兩項 i 和 j(i <= j),使得 Math.min(height[i], height[j]) * (j - i ...
Medium! 題目描述: 給定 n 個非負整數 a1,a2,...,an,每個數代表坐標中的一個點 (i, ai) 。畫 n 條垂直線,使得垂直線 i 的兩個端點分別為 (i, ai) 和 (i, 0)。找出其中的兩條線,使得它們與 x 軸共同構成的容器可以容納最多的水。 注意:你不能傾斜 ...
一、題目說明 11.Container With Most Water,這個題目難度是Medium。 二、我的做法 乍一看,簡單啊,兩個for循環就可以了,我在本地寫的。 提交后運行,居然Time Limit Exceeded是,好傷心。 里面給了一個非常長的數據,實際上我本地 ...
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
給定 n 個非負整數 a1,a2,...,an,每個數代表坐標中的一個點 (i, ai) 。畫 n 條垂直線,使得垂直線 i 的兩個端點分別為 (i, ai) 和 (i, 0)。找出其中的兩條線,使得它們與 x 軸共同構成的容器可以容納最多的水。 注意:你不能傾斜容器,n 至少是 ...
原題地址:https://oj.leetcode.com/problems/container-with-most-water/ 題意: Given n non-negative integers a1, a2, ..., an, where each represents a point ...
Container With Most Water 題目鏈接 Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines ...