C++ | Leetcode C++题解之第223题矩形面积

题目:

题解:

cpp 复制代码
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;
    }
};
相关推荐
苦藤新鸡2 小时前
8.最长的无重复字符的子串
c++·力扣
千金裘换酒2 小时前
LeetCode反转链表
算法·leetcode·链表
꧁Q༒ོγ꧂2 小时前
C++ 入门完全指南(四)--函数与模块化编程
开发语言·c++
汉克老师3 小时前
GESP2025年12月认证C++八级真题与解析(判断题8-10)
c++·快速排序··lcs·gesp八级·gesp8级
qq_433554543 小时前
C++ manacher(求解回文串问题)
开发语言·c++·算法
圣保罗的大教堂3 小时前
leetcode 1161. 最大层内元素和 中等
leetcode
闲看云起4 小时前
LeetCode-day6:接雨水
算法·leetcode·职场和发展
HL_风神4 小时前
设计原则之迪米特
c++·学习·设计模式
黛色正浓4 小时前
leetCode-热题100-贪心合集(JavaScript)
javascript·算法·leetcode
HL_风神4 小时前
设计原则之合成复用
c++·学习·设计模式