Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e7370b0

Browse files
committedSep 26, 2021
Add solution #11
1 parent 61ec915 commit e7370b0

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
8|[String to Integer (atoi)](./0008-string-to-integer-atoi.js)|Medium|
1616
9|[Palindrome Number](./0009-palindrome-number.js)|Easy|
1717
10|[Regular Expression Matching](./0010-regular-expression-matching.js)|Hard|
18+
11|[Container With Most Water](./0011-container-with-most-water.js)|Medium|
1819
12|[Integer to Roman](./0012-integer-to-roman.js)|Medium|
1920
13|[Roman to Integer](./0013-roman-to-integer.js)|Easy|
2021
14|[Longest Common Prefix](./0014-longest-common-prefix.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* 11. Container With Most Water
3+
* https://leetcode.com/problems/container-with-most-water/
4+
* Difficulty: Medium
5+
*
6+
* Given n non-negative integers `a1, a2, ..., an ,` where each represents a point at
7+
* coordinate `(i, ai)`. `n` vertical lines are drawn such that the two endpoints of
8+
* the line `i` is at `(i, ai)` and `(i, 0)`. Find two lines, which, together with the
9+
* x-axis forms a container, such that the container contains the most water.
10+
*
11+
* Notice that you may not slant the container.
12+
*/
13+
14+
/**
15+
* @param {number[]} height
16+
* @return {number}
17+
*/
18+
var maxArea = function(height) {
19+
let maxArea = 0;
20+
21+
for (let left = 0, right = height.length - 1; left < right;) {
22+
maxArea = Math.max(
23+
maxArea,
24+
Math.min(height[left], height[right]) * (right - left)
25+
);
26+
27+
if (height[left] < height[right]) {
28+
left++;
29+
} else {
30+
right--;
31+
}
32+
}
33+
34+
return maxArea;
35+
};

0 commit comments

Comments
 (0)
Please sign in to comment.