I thought this would be correct, it works for the four test cases given in the problem description but unfortunately failed for other test cases when submitted.

I first find the minx, maxx, miny, maxy. These four bounds determines a hull. The idea is that if there is no overlaps or gaps, then the area of the hull should be the sum of the areas of all rectangles. So what's wrong with this idea?

class Solution {

public:

bool isRectangleCover(vector<vector<int>>& rectangles) {

int xmin=INT_MAX,xmax=INT_MIN,ymin=INT_MAX,ymax=INT_MIN;

for(int i=0;i<rectangles.size();++i){

vector<int> tmp_rect = rectangles[i];

xmin = min(min(tmp_rect[0],tmp_rect[2]),xmin);

xmax = max(max(tmp_rect[0],tmp_rect[2]),xmax);

ymin = min(min(tmp_rect[1],tmp_rect[3]),ymin);

ymax = max(max(tmp_rect[1],tmp_rect[3]),ymax);

}

long real_area = 0;

for(int i=0;i<rectangles.size();++i){

vector<int> tmp_rect = rectangles[i];

real_area += abs(tmp_rect[2]-tmp_rect[0]) * abs(tmp_rect[3]-tmp_rect[1]);

}

long ideal_area = (xmax-xmin)*(ymax-ymin);

// cout << ideal_area << " " << real_area << endl;

return (ideal_area==real_area);

}

};