-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path836.java
More file actions
72 lines (63 loc) · 3.29 KB
/
836.java
File metadata and controls
72 lines (63 loc) · 3.29 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
__________________________________________________________________________________________________
Runtime: 0 ms
Memory Usage: 34.1 MB
class Solution {
public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
return(!(rec1[2]<=rec2[0]||rec1[3]<=rec2[1]||rec2[2]<=rec1[0]||rec2[3]<=rec1[1]));
}
}
__________________________________________________________________________________________________
sample 35244 kb submission
class Solution {
public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
int rec1PointX1 = rec1[0];
int rec1PointY1 = rec1[1];
int rec1PointX2 = rec1[2];
int rec1PointY2 = rec1[3];
int rec2PointX1 = rec2[0];
int rec2PointY1 = rec2[1];
int rec2PointX2 = rec2[2];
int rec2PointY2 = rec2[3];
boolean checkX1OnRec2X = betweenTwoPoints(rec1PointX1, rec2PointX1, rec2PointX2);
boolean checkX2OnRec2X = betweenTwoPoints(rec1PointX2, rec2PointX1, rec2PointX2);
boolean checkY1OnRec2Y = betweenTwoPoints(rec1PointY1, rec2PointY1, rec2PointY2);
boolean checkY2OnRec2Y = betweenTwoPoints(rec1PointY2, rec2PointY1, rec2PointY2);
boolean checkX1OnRec1X = betweenTwoPoints(rec2PointX1, rec1PointX1, rec1PointX2);
boolean checkX2OnRec1X = betweenTwoPoints(rec2PointX2, rec1PointX1, rec1PointX2);
boolean checkY1OnRec1X = betweenTwoPoints(rec2PointY1, rec1PointY1, rec1PointY2);
boolean checkY2OnRec1X = betweenTwoPoints(rec2PointY2, rec1PointY1, rec1PointY2);
System.out.println(checkX1OnRec2X + " " + checkX2OnRec2X + " " + checkY1OnRec2Y + " " + checkY2OnRec2Y + " " + checkX1OnRec1X
+ " " + checkX2OnRec1X + " " + checkY1OnRec1X + " " + checkY2OnRec1X);
return checkX1OnRec2X && checkY1OnRec2Y
|| checkX1OnRec2X && checkY2OnRec2Y
|| checkX1OnRec2X && checkY1OnRec1X
|| checkX1OnRec2X && checkY2OnRec1X
|| checkX2OnRec2X && checkY1OnRec2Y
|| checkX2OnRec2X && checkY2OnRec2Y
|| checkX2OnRec2X && checkY1OnRec1X
|| checkX2OnRec2X && checkY2OnRec1X
|| checkX1OnRec1X && checkY1OnRec2Y
|| checkX1OnRec1X && checkY2OnRec2Y
|| checkX1OnRec1X && checkY1OnRec1X
|| checkX1OnRec1X && checkY2OnRec1X
|| checkX2OnRec1X && checkY1OnRec2Y
|| checkX2OnRec1X && checkY2OnRec2Y
|| checkX2OnRec1X && checkY1OnRec1X
|| checkX2OnRec1X && checkY2OnRec1X;
}
public boolean betweenTwoPoints(int one, int two, int three)
{
return (two < one && one < three);
}
}
__________________________________________________________________________________________________
sample 35256 kb submission
class Solution {
public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
return isOverlap(rec1[0],rec1[2],rec2[0],rec2[2]) && isOverlap(rec1[1],rec1[3],rec2[1],rec2[3]);
}
private boolean isOverlap (int x1, int x2 , int x3, int x4){
if ((x4 > x1 && x3< x1) || (x2> x3 && x2 < x4) || (x1 >= x3 && x2 <= x4 ) || (x1<= x3 && x2 >=x4)) return true;
return false;
}
}