Amazon OA2 – 长方形覆盖

给两个长方形的topLeft和bottomRight坐标, 判断这两个长方形是否重叠

Rectangle Overlap。这题和leetcode 算相交面积的区别:它帮你定义好两个类,一个叫Point,一个叫Rectangle,Rectangle包括左上右下两个Point, Point包括x, y的值, 这种细节并不影响程序,总之一句判断直接通过了全部20多个case.

boolean doOverlap(Point l1, Point r1, Point l2, Point r2)
{
    // If one rectangle is on left side of other
    if (r2.x < l1.x || r1.x < l2.x)
        return false;
 
    // If one rectangle is above other
    if (r2.y > l1.y || r1.y > l2.y)
        return false;
 
    return true;
}

留下评论