File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ leetcode 测试
10
10
11
11
##### 包含的内容如下
12
12
13
+ https://leetcode.cn/problems/minimum-area-rectangle
14
+
13
15
https://leetcode.cn/problems/bulb-switcher/
14
16
15
17
https://leetcode.cn/problems/concatenated-words/
Original file line number Diff line number Diff line change
1
+ export default function minAreaRect ( points : number [ ] [ ] ) : number {
2
+ const ps = new Set ( points . map ( ( p ) => JSON . stringify ( p ) ) ) ;
3
+
4
+ let ans = Infinity ;
5
+ const n = points . length ;
6
+ for ( let i = 0 ; i < n ; i ++ ) {
7
+ for ( let j = i + 1 ; j < n ; j ++ ) {
8
+ if (
9
+ points [ i ] [ 0 ] !== points [ j ] [ 0 ] &&
10
+ points [ i ] [ 1 ] !== points [ j ] [ 1 ]
11
+ ) {
12
+ const area = Math . abs ( points [ j ] [ 0 ] - points [ i ] [ 0 ] ) *
13
+ Math . abs ( points [ j ] [ 1 ] - points [ i ] [ 1 ] ) ;
14
+ if ( area > ans ) continue ;
15
+ if (
16
+ ps . has ( JSON . stringify ( [ points [ i ] [ 0 ] , points [ j ] [ 1 ] ] ) ) &&
17
+ ps . has ( JSON . stringify ( [ points [ j ] [ 0 ] , points [ i ] [ 1 ] ] ) )
18
+ ) {
19
+ ans = Math . min (
20
+ ans ,
21
+ area ,
22
+ ) ;
23
+ }
24
+ }
25
+ }
26
+ }
27
+ return Number . isFinite ( ans ) ? ans : 0 ;
28
+ }
You can’t perform that action at this time.
0 commit comments