How to write code to achieve the container that holds the most water
This article mainly explains "how to write code to achieve the container that holds the most water". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. let's study and learn how to write code to achieve the container that holds the most water.
Description of the container with the most water in the title
Difficulty: medium
I will give you n non-negative integers, a _ 1, a _ 2, and a _ 1, where each number represents a point in coordinates (I, ai). Draw n vertical lines in the coordinates. The two endpoints of the vertical line I are (I, ai) and (I, 0), respectively. Find two of these lines so that the container composed of them and the x-axis can hold the most water.
Description: you cannot tilt the container
Input:] output: 49 explanation: the vertical line in the picture represents the input array [1, 8, 6, 2, 5, 4, 4, 3, 7]. In this case, the maximum value that the container can hold water (represented as the blue part) is 49
Example 2:
Input: height = [1jue 1] output: 1
Example 3:
Input: height = [4, 3, 2, 2, 1, 4] output: 16
Example 4:
Input: height = [1, 2, 1] output: 2
Prompt
N = height.length2 0) {y = y-1;} else {/ / the height corresponding to x