leetcode.11. Container With Most Water
轉向c++了,底乘高,低最大,面積再想大一點就得
class Solution { public: int maxArea(vector<int>& height) { int maxcon=0; int i=0; int h; int j=height.size()-1; while(i<j) { h=min(height[i],height[j]); //printf("%d %d %d",h,j,i); maxcon=max(maxcon,h*(j-i));//printf("\n%d",maxcon); while (height[i]<=h) i++; while (height[j]<=h) j--; } return maxcon; } };
保證高不斷拓高,低的那一邊就需要往上升到比原來高的地方才能提高容器。
相關推薦
LeetCode 11. Container With Most Water (裝最多水的容器)
cheng 個數 參考 找到 資料 算法題目 pointer etc html Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a
Leetcode:11- Container With Most Water
rms mos 谷歌 nat etc 翻譯 至少 leet each Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n
[LeetCode] 11. Container With Most Water 裝最多水的容器
OS python oge containe 較高的 contains tco water IT Given n non-negative integers a1, a2, ..., an, where each represents a point at coordina
Leetcode 11. Container With Most Water (two pointers)
oss else lee all pointer ide mov AR chan Leetcode: 11 there are two ways to deal with two pointers one is O(n), two pointers moves from b
Leetcode 11. Container With Most Water
如何盛最大的水? 陣列代表高度, 盛的水量V= min( height[left] 、 height[right] ) * 底部的長度= [right- left] 雙指標解決這個問題, 從左邊、右邊不
leetcode-11:Container With Most Water盛最多水的容器
題目: Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i,
leetCode 11 Container With Most Water
題目描述(中等難度) 每個陣列代表一個高度,選兩個任意的柱子往裡邊倒水,能最多倒多少水。 解法一 暴力解法 直接遍歷任意兩根柱子,求出能存水的大小,用一個變數儲存最大的。 public int maxArea(int[] height) { int
LeetCode 11. Container With Most Water(java)
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 end
[LeetCode]11. Container With Most Water 盛最多水的容器
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 endp
Leetcode 11. Container With Most Water 盛最多水的容器 解法
題目如下: Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn suc
leetcode.11. Container With Most Water
轉向c++了,底乘高,低最大,面積再想大一點就得 class Solution { public: int maxArea(vector<int>& height) { int maxcon=0; int i=0; i
LeetCode --- 11. Container With Most Water
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 endpoint
LeetCode-11-Container With Most Water
sla eas max nta height ive most raw coo 算法描述: Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate
[LeetCode]11. Container With Most Water解法及python
原題連結:https://leetcode.com/problems/container-with-most-water 最開始的想法是O(n2n2)的,即暴力的雙層迴圈,比較哪兩條線圍成的梯形或矩形
[C++]LeetCode 11: Container With Most Water(最大容積/最大矩形面積)
Problem: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn
LeetCode Notes_#11 Container with Most Water
LeetCode Notes_#11 Container with Most Water LeetCode Contents 題目 思路和解答 思路
【LeetCode】11. Container With Most Water - Java實現
文章目錄 1. 題目描述: 2. 思路分析: 3. Java程式碼: 1. 題目描述: Given n non-negative integers a[1], a[2], …, a[n] , where each represent
【LeetCode】11. Container With Most Water(盛最多水的容器)-C++實現的三種方法
本題是Bloomberg的面試題。 問題描述: 一、第一種方法-暴力解法 當我們在面試時想不到解題的方法時,不妨使用暴力解法,雙重遍歷陣列。 當 i = 0 時,使用指標 j 遍歷陣列,找到第一輪的最大值 area: 當i = 2 ,使用指標 j 遍歷
【Leetcode】11. Container With Most Water (medium)
11. Container With Most Water (medium) 描述 Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical l
【leetcode】11.Container With Most Water(c語言)
Description: Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines a