LeetCode-11 盛最多水的容器
- C++
class Solution { public: int maxArea(vector<int>& height) { int begin = 0; int end = height.size() - 1; int res = 0; while(begin!=end){ int temp = min(height[begin], height[end]) * (end - begin); if(res<temp){res = temp;} if(height[begin]>height[end]){end--;} else{begin++;} } return res; } };
相關推薦
[leetcode] 11.盛最多水的容器
scrip alt 分享 containe 可能性 其中 .com 大於 leetcode 盛最多水的容器 題意好繞,看半天都沒懂要幹什麽。 我直接上個圖可能就能一眼看明白了: 總之,當明白題意後,直接就能想到暴力法枚舉所有可能性,不過如果再畫一下圖基本就能發現:兩線段之
LeetCode 11 - 盛最多水的容器 - [雙指針暴力]
turn 怎麽 rip () 明顯 right 有一個 get 目前 題目鏈接:https://leetcode-cn.com/problems/container-with-most-water/description/ 給定 n 個非負整數 $a_1,a_2,\cdot
leetcode 11 盛最多水的容器
給定 n 個非負整數 a1,a2,...,an,每個數代表座標中的一個點 (i, ai) 。在座標內畫 n 條垂直線,垂直線 i 的兩個端點分別為 (i, ai) 和 (i, 0)。找出
[Leetcode] 11. 盛最多水的容器 java 二分查詢
給定 n 個非負整數 a1,a2,...,an,每個數代表座標中的一個點 (i, ai) 。在座標內畫 n 條垂直線,垂直線 i 的兩個端點分別為 (i, ai) 和 (i, 0)。找出其中的兩條線,使得它們與 x 軸共同構成的容器可以容納最多的水。 說明:你不能傾斜容
leetcode-11. 盛最多水的容器
var maxArea = function(height) { let max = Math.min(height[0],height[1]) for(let i=2;i<hei
leetcode 11.盛最多水的容器
給定 n 個非負整數 a1,a2,...,an,每個數代表座標中的一個點 (i, ai) 。在座標內畫 n 條垂直線,垂直線 i 的兩個端點分別為 (i, ai) 和 (i, 0)。找出其中的兩條線,使得它們與 x 軸共同構成的容器可以容納最多的水。 說明:你不能傾斜容器,
LeetCode-11 盛最多水的容器
C++ class Solution { public: int maxArea(vector<int>& height) { int begin = 0; int end = height.size() - 1;
LeetCode 11. 盛最多水的容器 Container With Most Water (C語言)
題目描述: 給定 n 個非負整數 a1,a2,…,an,每個數代表座標中的一個點 (i, ai) 。在座標內畫 n 條垂直線,垂直線 i 的兩個端點分別為 (i, ai) 和 (i, 0)。找出其中的兩條線,使得它們與 x 軸共同構成的容器可以容納最多的水。 說明:你不能傾斜容器
Leetcode 11. 盛最多水的容器(Python3)
11. 盛最多水的容器 給定 n 個非負整數 a1,a2,...,an,每個數代表座標中的一個點 (i, ai) 。在座標內畫 n 條垂直線,垂直線 i 的兩個端點分別為 (i, ai)
leetcode 11.盛最多水的容器(python)
給定 n 個非負整數 a1,a2,...,an,每個數代表座標中的一個點 (i, ai) 。在座標內畫 n 條垂直線,垂直線 i 的兩個端點分別為 (i, ai) 和 (i, 0)。找出其中的兩條線,使得它們與 x 軸共同構成的容器可以容納最多的水。 說明:你不能傾斜容器,
leetcode 11 盛最多水的容器 (C語言
給定 n 個非負整數 a1,a2,…,an,每個數代表座標中的一個點 (i, ai) 。在座標內畫 n 條垂直線,垂直線 i 的兩個端點分別為 (i, ai) 和 (i, 0)。找出其中的兩條線,使得它們與 x 軸共同構成的容器可以容納最多的水。 說明:你不能
leetCode 11. 盛最多水的容器 (swift)
給定 n 個非負整數 a1,a2,...,an,每個數代表座標中的一個點 (i, ai) 。在座標內畫 n 條垂直線,垂直線 i 的兩個端點分別為 (i, ai) 和 (i, 0)。找出其中的兩條線,使
LeetCode 11. 盛最多水的容器
題目描述 思路 理解 木桶效應:一隻木桶能盛多少水,並不取決於最長的那塊木板,而是取決於最短的那塊木板 顯然,這道題也是如此: 我們需要選擇兩塊相對長度較長
LeetCode:盛最多水的容器【11】
出發 UNC jpg 分析 左右 quest highlight 圖片 leetcode LeetCode:盛最多水的容器【11】 題目描述 給定 n 個非負整數 a1,a2,...,an,每個數代表坐標中的一個點 (i, ai) 。在坐標內畫 n 條垂直線,垂直線 i 的
Leetcode演算法Java全解答--11. 盛最多水的容器
Leetcode演算法Java全解答–11. 盛最多水的容器 題目 盛最多水的容器 題目描述提示幫助提交記錄社群討論閱讀解答 給定 n 個非負整數 a1,a2,…,an,每個數代表座標中的一個點 (i, ai) 。 在座標內畫 n 條垂直線,垂直線 i 的兩個端點分別為 (i
【LeetCode】11. 盛最多水的容器
題目連結:https://leetcode-cn.com/problems/container-with-most-water/description/ 題目描述 給定 n 個非負整數 a1,a2,…,an,每個數代表座標中的一個點 (i, ai) 。在座標內畫 n 條垂直線,垂
leetcode 11盛最多的水容器
題目 給定 n 個非負整數 a1,a2,…,an,每個數代表座標中的一個點 (i, ai) 。在座標內畫 n 條垂直線,垂直線 i 的兩個端點分別為 (i, ai) 和 (i, 0)。找出其中的兩條線,使得它們與 x 軸共同構成的容器可以容納最多的水。 說明:你不能傾斜容器,且 n 的值
【LeetCode】11. 盛最多水的容器(Container With Most Water)
【 英文練習 | 中文練習 】 題目描述: 給定 n 個非負數 a1,a2,…,an,每個數代表座標中的一個點 (i,ai)。在座標內畫 n 條垂直線,垂直線 i 的兩個端點分別為 (i,ai) 和 (i,0)。找出其中的兩條線,使得它們與 x 軸共同構成的容器可以容納最多的水。
LeetCode筆記 ------11. 盛最多水的容器
寫在前邊 本文為系列文章,記錄自己在leetcode上刷題的一些筆記,歡迎大家一塊兒討論。 題目描述 給定 n 個非負整數 a1,a2,…,an,每個數代表座標中的一個點 (i, ai) 。畫 n 條垂直線,使得垂直線 i 的兩個端點分別為 (i, ai
【LeetCode】11.盛最多水的容器
題目描述: 給定 n 個非負整數 a1,a2,...,an,每個數代表座標中的一個點 (i, ai) 。在座標內畫 n 條垂直線,垂直線 i 的兩個端點分別為 (i, ai) 和 (i, 0)。找出其中的兩條線,使得它們與 x 軸共同構成的容器可以容納最多的水。 說明:你