1
+ // Runtime: 32 ms (Top 17.31%) | Memory: 42.3 MB (Top 86.54%)
1
2
class Solution {
2
3
public int rectangleArea (int [][] rectangles ) {
3
4
int n = rectangles .length ;
@@ -7,12 +8,12 @@ public int rectangleArea(int[][] rectangles) {
7
8
coorx .add (rec [0 ]); coorx .add (rec [2 ]);
8
9
coory .add (rec [1 ]); coory .add (rec [3 ]);
9
10
}
10
-
11
+
11
12
Integer [] compressx = coorx .toArray (new Integer [0 ]);
12
13
Arrays .sort (compressx );
13
14
Integer [] compressy = coory .toArray (new Integer [0 ]);
14
15
Arrays .sort (compressy );
15
-
16
+
16
17
Map <Integer , Integer > mapx = new HashMap <>();
17
18
for (int i = 0 ; i < compressx .length ; i ++) {
18
19
mapx .put (compressx [i ], i );
@@ -21,7 +22,7 @@ public int rectangleArea(int[][] rectangles) {
21
22
for (int i = 0 ; i < compressy .length ; i ++) {
22
23
mapy .put (compressy [i ], i );
23
24
}
24
-
25
+
25
26
boolean [][] grid = new boolean [compressx .length ][compressy .length ];
26
27
for (int [] rec : rectangles ) {
27
28
for (int x = mapx .get (rec [0 ]); x < mapx .get (rec [2 ]); x ++) {
@@ -30,7 +31,7 @@ public int rectangleArea(int[][] rectangles) {
30
31
}
31
32
}
32
33
}
33
-
34
+
34
35
long res = 0L ;
35
36
for (int i = 0 ; i < grid .length ; i ++) {
36
37
for (int j = 0 ; j < grid [0 ].length ; j ++) {
@@ -42,4 +43,4 @@ public int rectangleArea(int[][] rectangles) {
42
43
res %= 1000000007 ;
43
44
return (int )res ;
44
45
}
45
- }
46
+ }
0 commit comments