Web这题最关键的是两点,一是两边往中间找,二是每次放弃最短的版。 WebProblem. You are given an integer array height of length n.There are n vertical lines drawn such that the two endpoints of the i th line are (i, 0) and (i, height[i]).. Find two lines that together with the x-axis form a container, such that the container contains the most water.
[C++] greedy to search global maximum height and width
WebSep 17, 2024 · 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 endpoints of the line i is at … WebNov 26, 2024 · Find two lines, which together with the x-axis form a container, such that the container contains the most water. Your program should return an integer that corresponds to the maximum area of water that can be contained ( Yes, we know maximum area instead of maximum volume sounds weird. But this is a 2D plane we are working with for … stim free pre workout jym
Solution: Container With Most Water - DEV Community
WebMar 17, 2024 · #include #include #include using namespace std; int largestRectangle(vector &heights) { int n = heights.size(); /* The stack … WebJan 29, 2024 · int largestRectangleArea (vector < int > & height) {int maxArea = 0; height. push_back (0); //why? coz 0 will always be lesser than than previous non zero stack element so we can calculate area of all previous element w.r.t it. stack < int > index; ... WebApr 3, 2024 · 题目描述 题解思路:两个边界哪个小,收缩哪个 123456789101112131415class Solution {public: int maxArea(vector& height) { … stim free preworkout