Skip to content

Commit 99fabad

Browse files
add js solution for 011
1 parent 2c89729 commit 99fabad

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const maxArea2 = function(height){
2+
let result = 0;
3+
for(let i = 0; i < height.length; i++){
4+
for(let j = i + 1; j < height.length; j++){
5+
result = Math.max(result, Math.min(height[i],height[j])*(j-i));
6+
}
7+
}
8+
return result;
9+
};
10+
11+
const maxArea = function(height){
12+
let result = 0, l = 0, r = height.length - 1;
13+
while(l < r){
14+
result = Math.max(result, Math.min(height[l],height[r])*(r-l));
15+
height[l] < height[r] ? l++ : r--;
16+
}
17+
return result;
18+
}

0 commit comments

Comments
 (0)