You are given a circle represented as (radius, xCenter, yCenter) and an axis-aligned rectangle represented as (x1, y1, x2, y2), where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-right corner of the rectangle.
Return true if the circle and rectangle are overlapped otherwise return false. In other words, check if there is any point (xi, yi) that belongs to the circle and the rectangle at the same time.
classSolution { boolintersect(int y1, int x1, int r, int y2, int x2){ return r * r >= abs(y1 - y2) * abs(y1 - y2) + abs(x1 - x2) * abs(x1 - x2); } boolinner(int y, int x, int x1, int y1, int x2, int y2){ return x1 <= x and x <= x2 and y1 <= y and y <= y2; } public: boolcheckOverlap(int radius, int xCenter, int yCenter, int x1, int y1, int x2, int y2){ if(inner(yCenter, xCenter, x1, y1, x2, y2)) returntrue; for(int i = x1; i <= x2; i++) { if(intersect(yCenter, xCenter, radius, y1, i) orintersect(yCenter, xCenter, radius, y2, i)) returntrue; } for(int i = y1; i <= y2; i++) { if(intersect(yCenter, xCenter, radius, i, x1) orintersect(yCenter, xCenter, radius, i, x2)) returntrue; } returnfalse; } };