No.190 - LeetCode836. Rectangle Overlap - 幾何 - 整點矩形相交判斷

條件:必須是整點矩形

思路:兩個矩形左下點中的右上點,必須在兩個矩形右上點中的左下點的左下側。

class Solution {
public:
    bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) {
        int x1 = max(rec1[0],rec2[0]);
        int y1 = max(rec1[1],rec2[1]);
        int x2 = min(rec1[2],rec2[2]);
        int y2 = min(rec1[3],rec2[3]);
        return x1 < x2 && y1 < y2;
    }
};
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章