Skip to content

Commit ef4c6a6

Browse files
authored
Create 3380-maximum-area-rectangle-with-point-constraints-i.js
1 parent 19b8f41 commit ef4c6a6

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @param {number[][]} points
3+
* @return {number}
4+
*/
5+
var maxRectangleArea = function (points) {
6+
const n = points.length
7+
const st = new Set()
8+
for (const i of points) st.add(i[0] + ',' + i[1])
9+
let res = -1
10+
11+
for (let i = 0; i < n; i++) {
12+
for (let j = i + 1; j < n; j++) {
13+
const x1 = points[i][0],
14+
y1 = points[i][1],
15+
x2 = points[j][0],
16+
y2 = points[j][1]
17+
if (x1 === x2 || y1 === y2) continue
18+
if (st.has(x1 + ',' + y2) && st.has(x2 + ',' + y1)) {
19+
const min1 = Math.min(x1, x2),
20+
max1 = Math.max(x1, x2),
21+
min2 = Math.min(y1, y2),
22+
max2 = Math.max(y1, y2)
23+
let isid = true
24+
for (const point of points) {
25+
const cx = point[0],
26+
cy = point[1]
27+
if (
28+
(cx > min1 && cx < max1 && cy > min2 && cy < max2) ||
29+
((cx === min1 || cx === max1) && cy > min2 && cy < max2) ||
30+
((cy === min2 || cy === max2) && cx > min1 && cx < max1)
31+
) {
32+
isid = false
33+
break
34+
}
35+
}
36+
if (isid) res = Math.max(res, (max1 - min1) * (max2 - min2))
37+
}
38+
}
39+
}
40+
return res
41+
}

0 commit comments

Comments
 (0)