C++ using simple math concept
initial thought:\nMy first thought is to list out all the way that two rectangle can overlap each other, then try to filter all the condition in the if else blo
**initial thought:**\nMy first thought is to list out all the way that two rectangle can overlap each other, then try to filter all the condition in the if else block.\n\n**Improvemed thought:**\nAfter drawing several picture on the paper, I found that the way **if  both X coordinate and Y coordinate are overlapped, the two rectangles are overlapped. So we can break down this question from 2D to 1D**\n\n**How to check if two lines are overlapped:**\nThis reminds me about the basic math concept I learned in school. So ***if the distance of two points at the very end is less than the sum of two lines\' length, the lines are overlapped***\n\nCode:\n```\nbool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) {\n        bool checkX = false;\n        bool checkY = false;\n        long rec1x1 = rec1[0], rec1y1 = rec1[1];\n        long rec1x2 = rec1[2], rec1y2 = rec1[3];\n        long rec2x1 = rec2[0], rec2y1 = rec2[1];\n        long rec2x2 = rec2[2], rec2y2 = rec2[3];\n        //check X coordinate\n        checkX = (max(rec1x2, rec2x2) - min(rec1x1, rec2x1)) < (rec1x2 - rec1x1 + rec2x2 - rec2x1);\n        //check Y coordinate\n        checkY = (max(rec1y2, rec2y2) - min(rec1y1, rec2y1)) < (rec1y2 - rec1y1 + rec2y2 - rec2y1);\n        return checkX && checkY;\n    }\n```
[]