您的位置:首页 > 其它

[LeetCode] Determine If Two Rectangles Overlap

2015-01-19 09:21 1526 查看
Question:

Given two axis-aligned rectangles A and B. Write a function to determine if the two rectangles overlap.

http://leetcode.com/2011/05/determine-if-two-rectangles-overlap.html
private static class Rectangle
{
public Point getLeftUp() {...}
public Point getRightDown() {...}
}

public void overlap(Rectangle a, Rectangle b)
{
Point p1 = a.getLeftUp();
Point p2 = a.getRightDown();

Point p3 = b.getLeftUp();
Point p4 = b.getRightDown();

boolean notouch =
p2.x < p3.x || p4.x < p1.x || p2.y < p3.y || p4.y < p1.y;
return !notouch;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LeetCode