Leetcode 223 Solution

This article provides solution to leetcode question 223 (rectangle-area)

https://leetcode.com/problems/rectangle-area

Solution

class Solution {
public:
    inline int64_t findOverlap(int x1, int x2, int x3, int x4)
    {
        return max((int64_t)min(x2, x4) - (int64_t)max(x1, x3), (int64_t)0);
    }

    int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        int64_t total = (int64_t)(C - A) * (int64_t)(D - B) + (int64_t)(G - E) * (int64_t)(H - F);
        return total - findOverlap(A, C, E, G) * findOverlap(B, D, F, H);
    }
};