We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f083ada commit 14d50acCopy full SHA for 14d50ac
939-minimum-area-rectangle.js
@@ -25,3 +25,26 @@ const minAreaRect = function(points) {
25
}
26
return res === Infinity ? 0 : res
27
};
28
+
29
+// another
30
31
+/**
32
+ * @param {number[][]} points
33
+ * @return {number}
34
+ */
35
+const minAreaRect = function (points) {
36
+ let ans = Infinity
37
+ const isPoint = {}
38
+ points.forEach(([x, y]) => (isPoint[x * 40000 + y] = true))
39
+ for (let idx1 = 0; idx1 < points.length - 1; idx1++) {
40
+ const [x1, y1] = points[idx1]
41
+ for (let idx2 = idx1 + 1; idx2 < points.length; idx2++) {
42
+ const [x2, y2] = points[idx2]
43
+ const area = Math.abs((x1 - x2) * (y1 - y2))
44
+ if (area === 0 || area >= ans) continue
45
+ if (isPoint[x1 * 40000 + y2] && isPoint[x2 * 40000 + y1]) ans = area
46
+ }
47
48
+ return ans !== Infinity ? ans : 0
49
+}
50
0 commit comments