Monday, January 7, 2019

836. Rectangle Overlap




class Solution {
    public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
                // x1 -> rec[0], y1 -> rec[1], x2 -> rec[2], y2 -> rec[3]
        /*
                         (x2a,y2a)
                (x1a,y1a)

                                                    (x2b,y2b)
                                        (x1b,y1b)
        */
        // b on top of a, b on left of a, b on bottom of a, b on the right of a
        return !(rec2[1] >= rec1[3] || rec2[2] <= rec1[0] || rec2[3] <= rec1[1] || rec2[0] >= rec1[2]);
       
    }
}

No comments:

Post a Comment