Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ae97c9

Browse files
committed
area
1 parent96ee98d commit6ae97c9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎twoPoints/MaxArea.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
packageAlgorithms.twoPoints;
2+
3+
publicclassMaxArea {
4+
publicintmaxArea(int[]height) {
5+
if (height ==null) {
6+
return0;
7+
}
8+
9+
intleft =0;
10+
intright =height.length -1;
11+
intmaxArea =0;
12+
13+
while (left <right) {
14+
inth =Math.min(height[left],height[right]);
15+
intarea =h * (right -left);
16+
maxArea =Math.max(maxArea,area);
17+
18+
if (height[left] <height[right]) {
19+
// 如果左边界比较低,尝试向右寻找更高的边界
20+
left++;
21+
}else {
22+
// 如果右边界比较低,尝试向左寻找更高的边界
23+
right--;
24+
}
25+
}
26+
27+
returnmaxArea;
28+
}
29+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp