deno.land / x / masx200_leetcode_test@10.6.5 / minimum-area-rectangle / index.ts

نووسراو ببینە
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
export default function minAreaRect(points: number[][]): number { const ps = new Set(points.map((p) => JSON.stringify(p)));
let ans = Infinity; const n = points.length; for (let i = 0; i < n; i++) { for (let j = i + 1; j < n; j++) { if ( points[i][0] !== points[j][0] && points[i][1] !== points[j][1] ) { const area = Math.abs(points[j][0] - points[i][0]) * Math.abs(points[j][1] - points[i][1]); if (area > ans) continue; if ( ps.has(JSON.stringify([points[i][0], points[j][1]])) && ps.has(JSON.stringify([points[j][0], points[i][1]])) ) { ans = Math.min( ans, area, ); } } } } return Number.isFinite(ans) ? ans : 0;}
masx200_leetcode_test

Version Info

Tagged at
a year ago