classSolution{public:boolisRectangleCover(vector<vector<int>>&rectangles){intarea=0;intx1=INT_MAX;inty1=INT_MAX;intx2=INT_MIN;inty2=INT_MIN;unordered_set<string>corners;for(constvector<int>&r:rectangles){area+=(r[2]-r[0])*(r[3]-r[1]);x1=min(x1,r[0]);y1=min(y1,r[1]);x2=max(x2,r[2]);y2=max(y2,r[3]);// Four points of current rectangleconstvector<string>points{to_string(r[0])+" "+to_string(r[1]),to_string(r[0])+" "+to_string(r[3]),to_string(r[2])+" "+to_string(r[1]),to_string(r[2])+" "+to_string(r[3])};for(conststring&point:points)if(!corners.insert(point).second)corners.erase(point);}if(corners.size()!=4)returnfalse;if(!corners.count(to_string(x1)+" "+to_string(y1))||!corners.count(to_string(x1)+" "+to_string(y2))||!corners.count(to_string(x2)+" "+to_string(y1))||!corners.count(to_string(x2)+" "+to_string(y2)))returnfalse;returnarea==(x2-x1)*(y2-y1);}};
classSolution{publicbooleanisRectangleCover(int[][]rectangles){intarea=0;intx1=Integer.MAX_VALUE;inty1=Integer.MAX_VALUE;intx2=Integer.MIN_VALUE;inty2=Integer.MIN_VALUE;Set<String>corners=newHashSet<>();for(int[]r:rectangles){area+=(r[2]-r[0])*(r[3]-r[1]);x1=Math.min(x1,r[0]);y1=Math.min(y1,r[1]);x2=Math.max(x2,r[2]);y2=Math.max(y2,r[3]);// Four points of current rectangleString[]points=newString[]{r[0]+" "+r[1],r[0]+" "+r[3],r[2]+" "+r[1],r[2]+" "+r[3]};for(finalStringpoint:points)if(!corners.add(point))corners.remove(point);}if(corners.size()!=4)returnfalse;if(!corners.contains(x1+" "+y1)||!corners.contains(x1+" "+y2)||!corners.contains(x2+" "+y1)||!corners.contains(x2+" "+y2))returnfalse;returnarea==(x2-x1)*(y2-y1);}}