GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode/code/lc11.java at master · mJackie/leetcode

Expand file tree

/

lc11.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
29 lines (28 loc) · 890 Bytes
/

lc11.java

Copy path

File metadata and controls

29 lines (28 loc) · 890 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package code;
/*
* 11. Container With Most Water
* 题意:数组下标代表横坐标,数组中的值代表纵坐标,求最大面积
* 难度:Medium
* 分类:Array, Two Pointers
* Tips:复杂度可以为O(N), 指针往里走, 若值也小了,则面积一定不会增大。和lc42做比较
* lc11, lc42, lc84
*/
public class lc11 {
public static void main(String[] args) {
int[] arr = {1,8,6,2,5,4,8,3,7};
System.out.println(maxArea(arr));
}
public static int maxArea(int[] height) {
int left = 0;
int right = height.length-1;
int result = 0;
while(left<right){
result = Math.max( result, Math.min(height[left],height[right])*(right-left) );
if(height[left]<height[right])
left++;
else
right--;
}
return result;
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.