-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1401.cpp
30 lines (29 loc) · 1.04 KB
/
1401.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution {
public:
bool checkOverlap(int radius, int xCenter, int yCenter, int x1, int y1, int x2, int y2) {
if (xCenter < x2 && xCenter > x1 && yCenter < y2 && yCenter > y1) {
return true;
}
if (((y1 <= yCenter + radius && y1 >= yCenter) ||
(y2 >= yCenter - radius && y2 <= yCenter)) &&
xCenter >= x1 && xCenter <= x2) {
return true;
}
if (yCenter <= y2 && yCenter >= y1 &&
((xCenter - radius <= x2 && xCenter >= x2) ||
(xCenter + radius >= x1 && xCenter <= x1))) {
return true;
}
if (square(xCenter - x1) + square(yCenter - y1) <= square(radius) ||
square(xCenter - x1) + square(yCenter - y2) <= square(radius) ||
square(xCenter - x2) + square(yCenter - y1) <= square(radius) ||
square(xCenter - x2) + square(yCenter - y2) <= square(radius)) {
return true;
}
return false;
}
private:
int square(int n) {
return n * n;
}
};