-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
48 lines (40 loc) · 1.24 KB
/
Copy pathSolution.java
File metadata and controls
48 lines (40 loc) · 1.24 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
public class Solution {
public static void main(String[] args) {
int A = -1500000001;
int B = 0;
int C = -1500000000;
int D = 1;
int E = 1500000000;
int F = 0;
int G = 1500000001;
int H = 1;
int ac = C - A;
int bd = D - B;
int eg = G - E;
int fh = H - F;
int area1 = ac * bd;
// System.out.println(area1);
int area2 = eg * fh;
// System.out.println(area2);
long length = Math.max((long)Math.min(C, G) - (long)Math.max(A, E), 0);
// System.out.println(Math.min(C, G));
// System.out.println(Math.max(A, E));
System.out.println(length);
long height = Math.max(Math.min(D, H) - Math.max(B, F), 0);
System.out.println(height);
long area3 = length * height;
// System.out.println(area1 + area2 - area3);
}
public static int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int ac = C - A;
int bd = D - B;
int eg = G - E;
int fh = H - F;
int area1 = ac * bd;
int area2 = eg * fh;
int length = Math.max(Math.min(C, G) - Math.max(A, E), 0);
int height = Math.max(Math.min(D, H) - Math.max(B, F), 0);
int area3 = length * height;
return area1 + area2 - area3;
}
}