223. Rectangle Area
题目:
https://leetcode.com/problems/add-two-numbers/
难度 : Easy
这道题是我瞎了狗眼,🐶,之前看错了,以为要求相交的部分,结果是求cover的部分,所以写的长||||||
class Solution(object):
def computeArea(self, A, B, C, D, E, F, G, H):
"""
:type A: int
:type B: int
:type C: int
:type D: int
:type E: int
:type F: int
:type G: int
:type H: int
:rtype: int
"""
return self.area(C - A, D - B) + self.area(H - F, G - E ) - self.area(self.interSect(A,C,E,G), self.interSect(B,D,F,H))
def area(self, w, h):
if w * h < 0:
return - w * h
return w * h
def interSect(self, A, C, E, G):
if E > C:
return 0
elif G < A:
return 0
elif E >= A and G <= C:
return G - E
elif A >= E and C <= G:
return C - A
elif G <= C and G >= A and E <= A:
return G - A
else:
return C - E