Data Structure & Algorithm: Level-1 Problem #44. Overlap Rectangle

On a Cartesian coordinate system, a rectangle can be described as a two-dimensional set: ( (x1, y1), (x2, y2)), where (x1, y1) is the coordinate of its bottom-left corner, and (x2, y2) is the coordinate of its top-right corner. Note that the horizontal edges (top and bottom) are parallel to the X-axis, and the vertical edges (left and right) are parallel to the Y-axis.

Given two rectangles, find out whether they are overlapping or not.

Sample Input:

rec1 = ((1 ,1), (5, 5)), rec2 = ((2, 2), (7, 7))

Sample Output:

True

Overlap Rectangle


数据结构和算法:初级练习题 #44 – 重叠矩形


在平面坐标上,矩形可以由两个坐标点表示,也就是矩形的左下角和右上角。所以一个矩形的位置可以表示为:((x1, y1), (x2, y2))。其中(x1, y1)为矩形左下角坐标,(x2,y2)为矩形右上角坐标。

给定两个矩形的平面坐标,检查它们是否会重叠。

输入样例:

rec1 = ((1 ,1), (5, 5)), rec2 = ((2, 2), (7, 7))

输出样例:

True

Python Solution

Overlap Rectangle