class Solution {
public:
int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
int area1 = (ax2 - ax1) * (ay2 - ay1), area2 = (bx2 - bx1) * (by2 - by1);
int overlapWidth = min(ax2, bx2) - max(ax1, bx1), overlapHeight = min(ay2, by2) - max(ay1, by1);
int overlapArea = max(overlapWidth, 0) * max(overlapHeight, 0);
return area1 + area2 - overlapArea;
}
};
相关文章
- 07-09C++ | Leetcode C++题解之第223题矩形面积-题解:
- 07-09【C++ STL】模拟实现 vector
- 07-09【C++】IO流
- 07-09RocketMQ之消费者,重平衡机制与流程详解附带源码解析-2. 概要设计
- 07-09C++继承(一文说懂)-四:🔥派生类的默认成员函数
- 07-09Golang | Leetcode Golang题解之第214题最短回文串-题解:
- 07-09数据结构第07节:队列
- 07-09C++类的成员:静态成员变量、静态成员函数、非静态成员变量、非静态成员函数
- 07-09LeetCode 290. 单词规律
- 07-09定个小目标之刷LeetCode热题(42)