Skip to content

Commit 3f9131c

Browse files
committed
三刷11
1 parent f46dbcb commit 3f9131c

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

docs/0011-container-with-most-water.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ include::{sourcedir}/_0011_ContainerWithMostWater.java[tag=answer]
4949
include::{sourcedir}/_0011_ContainerWithMostWater_2.java[tag=answer]
5050
----
5151
--
52+
53+
三刷::
54+
+
55+
--
56+
[{java_src_attr}]
57+
----
58+
include::{sourcedir}/_0011_ContainerWithMostWater_3.java[tag=answer]
59+
----
60+
--
5261
====
5362

5463
== 参考资料

logbook/202406.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,11 @@
650650
|{doc_base_url}/0064-minimum-path-sum.adoc[题解]
651651
|✅动态规划
652652

653+
|{counter:codes}
654+
|{leetcode_base_url}/container-with-most-water/[11. Container With Most Water^]
655+
|{doc_base_url}/0011-container-with-most-water.adoc[题解]
656+
|⭕️双指针+贪心
657+
653658
|===
654659

655660
截止目前,本轮练习一共完成 {codes} 道题。
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.diguage.algo.leetcode;
2+
3+
public class _0011_ContainerWithMostWater_3 {
4+
// tag::answer[]
5+
6+
/**
7+
* @author D瓜哥 · https://www.diguage.com
8+
* @since 2024-09-16 19:38:05
9+
*/
10+
public int maxArea(int[] height) {
11+
int result = 0;
12+
int left = 0, right = height.length - 1;
13+
while (left < right) {
14+
result = Math.max(result,
15+
Math.min(height[left], height[right]) * (right - left - 1));
16+
if (height[left] < height[right]) {
17+
left++;
18+
} else {
19+
right--;
20+
}
21+
}
22+
return result;
23+
}
24+
// end::answer[]
25+
}

0 commit comments

Comments
 (0)