Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write code to achieve the container that holds the most water

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report