Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd704afc

Browse files
refactor 391
1 parentb4f2bb1 commitd704afc

File tree

1 file changed

+4
-54
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-54
lines changed

‎src/main/java/com/fishercoder/solutions/_391.java

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,11 @@
33
importjava.util.HashSet;
44
importjava.util.Set;
55

6-
/**
7-
* 391. Perfect Rectangle
8-
*
9-
* Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover of a rectangular region.
10-
Each rectangle is represented as a bottom-left point and a top-right point.
11-
For example, a unit square is represented as [1,1,2,2]. (coordinate of bottom-left point is (1, 1) and top-right point is (2, 2)).
12-
13-
Example 1:
14-
15-
rectangles = [
16-
[1,1,3,3],
17-
[3,1,4,2],
18-
[3,2,4,4],
19-
[1,3,2,4],
20-
[2,3,3,4]
21-
]
22-
23-
Return true. All 5 rectangles together form an exact cover of a rectangular region.
24-
25-
Example 2:
26-
27-
rectangles = [
28-
[1,1,2,3],
29-
[1,3,2,4],
30-
[3,1,4,2],
31-
[3,2,4,4]
32-
]
33-
34-
Return false. Because there is a gap between the two rectangular regions.
35-
36-
Example 3:
37-
38-
rectangles = [
39-
[1,1,3,3],
40-
[3,1,4,2],
41-
[1,3,2,4],
42-
[3,2,4,4]
43-
]
44-
45-
Return false. Because there is a gap in the top center.
46-
47-
Example 4:
48-
49-
rectangles = [
50-
[1,1,3,3],
51-
[3,1,4,2],
52-
[1,3,2,4],
53-
[2,2,4,4]
54-
]
55-
56-
Return false. Because two of the rectangles overlap with each other.
57-
*/
586
publicclass_391 {
597
publicstaticclassSolution1 {
60-
/** credit: https://discuss.leetcode.com/topic/56052/really-easy-understanding-solution-o-n-java */
8+
/**
9+
* credit: https://discuss.leetcode.com/topic/56052/really-easy-understanding-solution-o-n-java
10+
*/
6111
publicbooleanisRectangleCover(int[][]rectangles) {
6212
if (rectangles.length ==0 ||rectangles[0].length ==0) {
6313
returnfalse;
@@ -99,7 +49,7 @@ public boolean isRectangleCover(int[][] rectangles) {
9949
}
10050

10151
if (!set.contains(x1 +" " +y1) || !set.contains(x1 +" " +y2) || !set.contains(
102-
x2 +" " +y1) || !set.contains(x2 +" " +y2) ||set.size() !=4) {
52+
x2 +" " +y1) || !set.contains(x2 +" " +y2) ||set.size() !=4) {
10353
returnfalse;
10454
}
10555

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp