Skip to content

Commit 08d62b8

Browse files
committed
Runtime: 32 ms (Top 17.31%) | Memory: 42.3 MB (Top 86.54%)
1 parent 6e92b7e commit 08d62b8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

scripts/algorithms/R/Rectangle Area II/Rectangle Area II.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 32 ms (Top 17.31%) | Memory: 42.3 MB (Top 86.54%)
12
class Solution {
23
public int rectangleArea(int[][] rectangles) {
34
int n = rectangles.length;
@@ -7,12 +8,12 @@ public int rectangleArea(int[][] rectangles) {
78
coorx.add(rec[0]); coorx.add(rec[2]);
89
coory.add(rec[1]); coory.add(rec[3]);
910
}
10-
11+
1112
Integer[] compressx = coorx.toArray(new Integer[0]);
1213
Arrays.sort(compressx);
1314
Integer[] compressy = coory.toArray(new Integer[0]);
1415
Arrays.sort(compressy);
15-
16+
1617
Map<Integer, Integer> mapx = new HashMap<>();
1718
for(int i = 0; i < compressx.length; i++) {
1819
mapx.put(compressx[i], i);
@@ -21,7 +22,7 @@ public int rectangleArea(int[][] rectangles) {
2122
for(int i = 0; i < compressy.length; i++) {
2223
mapy.put(compressy[i], i);
2324
}
24-
25+
2526
boolean[][] grid = new boolean[compressx.length][compressy.length];
2627
for (int[] rec: rectangles) {
2728
for (int x = mapx.get(rec[0]); x < mapx.get(rec[2]); x++) {
@@ -30,7 +31,7 @@ public int rectangleArea(int[][] rectangles) {
3031
}
3132
}
3233
}
33-
34+
3435
long res = 0L;
3536
for (int i = 0; i < grid.length; i++) {
3637
for (int j = 0; j < grid[0].length; j++) {
@@ -42,4 +43,4 @@ public int rectangleArea(int[][] rectangles) {
4243
res %= 1000000007;
4344
return (int)res;
4445
}
45-
}
46+
}

0 commit comments

Comments
 (0)