# perfect rectangle

• class Solution {
public:
bool isRectangleCover(vector<vector<int>>& rectangles) {

bool flag = 0;
bool temp_flag = 1;
int count = rectangles.size();
int total_area = 0;
int temp_area = 0;
int left_x = rectangles[0][0], left_y = rectangles[0][1], right_x = rectangles[0][2], right_y = rectangles[0][3];
//int temp_x = rectangles[0][2], temp_y = rectangles[0][3];
int temp_x = 0, temp_y = 0;
if (count>1){

for (int i = 0; i < count; i++){
if (temp_flag){
//if (rectangles[i][0] < temp_x && temp_x < rectangles[i][2]) a = 1;

for (int j = 0; j < count; j++){
if (i != j){
if ((rectangles[j][0] < rectangles[i][2] && rectangles[i][2] <= rectangles[j][2]) && (rectangles[j][1] < rectangles[i][3] && rectangles[i][3] <= rectangles[j][3])) temp_flag = 0;
}

}

temp_area += (rectangles[i][2] - rectangles[i][0])*(rectangles[i][3] - rectangles[i][1]);
if (rectangles[i][0] < left_x) left_x = rectangles[i][0];//左下x
//else left_x = rectangles[i + 1][0];
if (rectangles[i][1] < left_y) left_y = rectangles[i][1];//左下y
//else left_y = rectangles[i + 1][1];
if (rectangles[i][2] > right_x) right_x = rectangles[i][2];//右上x
//else right_x = rectangles[i + 1][2];
if (rectangles[i][3] > right_y) right_y = rectangles[i][3];//右上y
//else right_y = rectangles[i + 1][3];
}
}
//temp_area += (rectangles[count-1][2] - rectangles[count-1][0])*(rectangles[count-1][3] - rectangles[count-1][1]);
total_area = (right_x - left_x)*(right_y - left_y);
}
else if (count == 1) flag = 1;

if (total_area == temp_area && temp_flag == 1) flag = 1;

return flag;

}

};

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.