0%

[題解]Leetcode 1401 Circle and Rectangle Overlapping

1401 Circle and Rectangle Overlapping

題目連結

1
2
3
4
5
6
7
8
class Solution {
public:
bool checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2) {
int x = clamp(x_center,x1,x2) - x_center;
int y = clamp(y_center,y1,y2) - y_center;
return x*x + y*y <= radius * radius;
}
};