先思考一维的情况:两条相交的直线的两端点坐标情况为:x1 x3 x2 x4或者是 x3 x1 x4 x2。这样都能导出需要满足的条件是x1<x4&&x3<x2。二维的问题一样,就是加入的纵坐标。
class Solution {
public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
return rec1[0]<rec2[2]&&rec2[0]<rec1[2]&&rec1[1]<rec2[3]&&rec2[1]<rec1[3];
}
}