Golang solution faster than 100% with explanation and images
Code On The Bottom, If This Helps Please Up Vote\n\nThis solution is pretty simular to my other solution Leetcode: 223 This is the part in the other solution wh
**Code On The Bottom, If This Helps Please Up Vote**\n\nThis solution is pretty simular to my other solution [Leetcode: 223](https://nathannaveen.dev/posts/leetcode-223/) This is the part in the other solution which I based this solution on:\n\n``` go\n// A = rec1[0], B = rec1[1], C = rec1[2], D = rec1[3]\n// E = rec2[0], F = rec2[1], G = rec2[2], H = rec2[3]\nleft, right := max(A, E), min(G, C)\nup, down := min(D, H), max(F, B)\n\nif right > left && up > down {\n    sum -= (right - left) * (up - down) // overlap\n}\n```\n\nThe idea of this solution can be shown using some images:\n\nWe can get the input `[1, 1, 3, 3], [2, 2, 7, 6]` and graph it:\n\n![image](https://assets.leetcode.com/users/images/e08b2374-c556-44b8-8847-de422efe386c_1615396115.1769323.png)\n![image](https://assets.leetcode.com/users/images/a07996ae-eeb6-496b-9307-6e6766f32ba9_1615396125.011349.png)\n\n\nAnd when the `left, right, up, down` lines are shown we get the overlap. We can find the `left, right, up, down` lines by doing the folowing:\n\n* `Left =` the maximum of `rec1 x1` and `rec2 x1`, and as you can see `rec2 x1` is `left` because it is greater than `rec1 x1`\n* `Right =` the minimum of `rec1 x2` and `rec2 x2`. As we can see `right` is `rec1 x1`.\n* `Down =` the maximum of `rec1 y1` and `rec2 y1`. As we can also see the max is `rec2 y1`.\n* `Up =` the minimum of `rec1 y2` and `rec2 y2`. Al we can see the min is `rec1 y2`.\n\nAnd now you can see that this is how we find whether there is an overlap.\n\n``` go\nfunc isRectangleOverlap(rec1 []int, rec2 []int) bool {\n\n    left, right := max(rec1[0], rec2[0]), min(rec1[2], rec2[2])\n    up, down := min(rec1[3], rec2[3]), max(rec1[1], rec2[1])\n\n    if right > left && up > down {\n        return true\n    }\n\n    return false\n\n}\n\nfunc max(a, b int) int {\n    if a < b {\n        return b\n    }\n    return a\n}\n\nfunc min(a, b int) int {\n    if a < b {\n        return a\n    }\n    return b\n}\n```
['Go']