1401. Circle and Rectangle Overlapping Medium
1/**
2 * [1401] Circle and Rectangle Overlapping
3 *
4 * 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.
5 * 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.
6 *
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2020/02/20/sample_4_1728.png" style="width: 258px; height: 167px;" />
9 * Input: radius = 1, xCenter = 0, yCenter = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1
10 * Output: true
11 * Explanation: Circle and rectangle share the point (1,0).
12 *
13 * Example 2:
14 *
15 * Input: radius = 1, xCenter = 1, yCenter = 1, x1 = 1, y1 = -3, x2 = 2, y2 = -1
16 * Output: false
17 *
18 * Example 3:
19 * <img alt="" src="https://assets.leetcode.com/uploads/2020/02/20/sample_2_1728.png" style="width: 150px; height: 135px;" />
20 * Input: radius = 1, xCenter = 0, yCenter = 0, x1 = -1, y1 = 0, x2 = 0, y2 = 1
21 * Output: true
22 *
23 *
24 * Constraints:
25 *
26 * 1 <= radius <= 2000
27 * -10^4 <= xCenter, yCenter <= 10^4
28 * -10^4 <= x1 < x2 <= 10^4
29 * -10^4 <= y1 < y2 <= 10^4
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/circle-and-rectangle-overlapping/
35// discuss: https://leetcode.com/problems/circle-and-rectangle-overlapping/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn check_overlap(radius: i32, x_center: i32, y_center: i32, x1: i32, y1: i32, x2: i32, y2: i32) -> bool {
41 false
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_1401() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.