-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11.js
More file actions
32 lines (27 loc) · 737 Bytes
/
11.js
File metadata and controls
32 lines (27 loc) · 737 Bytes
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
30
31
32
var maxArea = function(height) {
var maxar=0;
var head=0,tail=height.length-1;
var h,area;
while(head<tail){
area = Math.min(height[head],height[tail])*(tail-head);
if(area>maxar){
maxar = area;
}
h = Math.min(height[head],height[tail]);
while(height[head]<=h)head++;
while(height[tail]<=h)tail--;
}
return maxar;
};
//========fastest======
var maxArea = function(height) {
var maxar=0;
var head=0,tail=height.length-1;
var h,area;
while(head<tail){
maxar=Math.max(maxar,Math.min(height[head],height[tail])*(tail-head));
if(height[head]<height[tail]){head++;}
else{tail--;}
}
return maxar;
};