-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11.js
More file actions
28 lines (27 loc) · 776 Bytes
/
11.js
File metadata and controls
28 lines (27 loc) · 776 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
/**
* @param {number[]} height
* @return {number}
*/
var maxArea = function (height) {
let left = 0, right = height.length - 1, res = 0
while (left < right) {
res = Math.max(res, (right - left) * Math.min(height[left], height[right]))
height[left] >= height[right] ? right-- : left++
}
return res
/*
let res = 0, n = height.length
for (let i = 0; i < n - 1; i++) {
for (let j = i + 1; j < n; j++) {
res = Math.max(res, (j - i) * Math.min(height[i], height[j]))
}
}
return res
*/
};
/*
2021/9/14
54 39
双指针,分别从两侧向中间逼近,每次移动高度较低的那个指针,复杂度N
两个for循环,复杂度N^2
*/