223. Rectangle Area Medium

@problem@discussion
#Math#Geometry



1/**
2 * [223] Rectangle Area
3 *
4 * Given the coordinates of two rectilinear rectangles in a 2D plane, return the total area covered by the two rectangles.
5 * The first rectangle is defined by its bottom-left corner (ax1, ay1) and its top-right corner (ax2, ay2).
6 * The second rectangle is defined by its bottom-left corner (bx1, by1) and its top-right corner (bx2, by2).
7 *  
8 * Example 1:
9 * <img alt="Rectangle Area" src="https://assets.leetcode.com/uploads/2021/05/08/rectangle-plane.png" style="width: 700px; height: 365px;" />
10 * Input: ax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2
11 * Output: 45
12 * 
13 * Example 2:
14 * 
15 * Input: ax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -2, by1 = -2, bx2 = 2, by2 = 2
16 * Output: 16
17 * 
18 *  
19 * Constraints:
20 * 
21 * 	-10^4 <= ax1 <= ax2 <= 10^4
22 * 	-10^4 <= ay1 <= ay2 <= 10^4
23 * 	-10^4 <= bx1 <= bx2 <= 10^4
24 * 	-10^4 <= by1 <= by2 <= 10^4
25 * 
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/rectangle-area/
30// discuss: https://leetcode.com/problems/rectangle-area/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35    pub fn compute_area(ax1: i32, ay1: i32, ax2: i32, ay2: i32, bx1: i32, by1: i32, bx2: i32, by2: i32) -> i32 {
36        0
37    }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_223() {
48    }
49}
50


Back
© 2025 bowen.ge All Rights Reserved.