Skip to content

Commit 6ec05b8

Browse files
committed
Added 1 solution
1 parent 7863965 commit 6ec05b8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Medium/Rectangle Area.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
3+
int area = ((D - B) * (C - A)) + ((H - F) * (G- E));
4+
area -= overlap(A, C, E, G) * overlap(B, D, F, H);
5+
return area;
6+
}
7+
8+
private int overlap(int x1, int x2, int x3, int x4) {
9+
if (x2 <= x3) {
10+
return 0;
11+
}
12+
13+
if (x1 >= x4) {
14+
return 0;
15+
}
16+
17+
return Math.min(x2, x4) - Math.max(x1, x3);
18+
}
19+
}

0 commit comments

Comments
 (0)