Problem : https://leetcode.com/problems/rectangle-area/
(C, D) +------------+ | | | | (L, M ) | +------+------+ (G, H) | | | | +-----+------+ | (A,B) |(I, J) | | | +-------------+ (E,F)
class Solution:
def computeArea(self, A: int, B: int, C: int, D: int, E: int, F: int, G: int, H: int) -> int:
def overlapping():
I = max(A, E)
J = max(B, F)
L = min(C, G)
M = min(D, H)
if L > I and M > J:
return (L - I) * (M - J)
return 0
area1 = (C - A) * (D - B)
area2 = (G - E) * (H - F)
return area1 + area2 - overlapping()
No comments:
Post a Comment