LeetCode刷题笔记 836. 矩形重叠 【二维->一维投影】

图解:将矩形重叠问题转化为区间重叠问题(C++/Java/Python)

bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) {
     
    bool x_overlap = !(rec1[2] <= rec2[0] || rec2[2] <= rec1[0]);
    bool y_overlap = !(rec1[3] <= rec2[1] || rec2[3] <= rec1[1]);
    return x_overlap && y_overlap;
}

你可能感兴趣的:(LeetCode刷题笔记 836. 矩形重叠 【二维->一维投影】)