【面】判断两个矩形是否相交

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution:
def isRectangleOverlap(self, rec1, rec2):
x1 = max(rec1[0], rec2[0])
y1 = max(rec1[1], rec2[1])

x2 = min(rec1[2], rec2[2])
y2 = min(rec1[3], rec2[3])

if x1 < x2 and y1 < y2:
return True
else:
return False

if __name__=='__main__':
s = Solution()
print(s.isRectangleOverlap([0,0,2,2], [1,1,3,3]))
print(s.isRectangleOverlap([0,0,1,1], [1,0,2,1]))
0%