The above vertical lines are representedbyarray [1,8,6,2,5,4,8,3,7]. Inthiscase,the max area ofwater(blue section) the container can containis49. solution### 第一种解法:暴力解法,也是最容易想到的解法 Copy classSolution{publicintmaxArea(int[] height){intmax =0;for(inti =0; i < ...
leetcode-solution 很好的解释,通过动态规划的思想(类似最短路径的求解思想),或反证法可以证明算法的正确性。 code #include<iostream>#include<vector>#include<algorithm>usingnamespacestd;classSolution{public:intmaxArea(vector<int>& height){intmaximum =0;intileft =0, iright = height.size() -1;while(...
leetcode_medium_array problem 11. Container With Most Water solution #1: code 参考 1. leetcode_11. Container With Most Water; 完
leetcode 11. Container With Most Water 、42. Trapping Rain Water 、238. Product of Array Except Self 、407. Trapping Rain Water II 11. Container With Most Water https://www.cnblogs.com/grandyang/p/4455109.html 用双指针向中间滑动,较小的高度就作为当前情况的高度,然后循环找容量的最大值。 不...
Note: You may not slant the container andnis at least 2. The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49. Example: ...