You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.2 KiB
68 lines
2.2 KiB
public class L0085 {
|
|
public static void main(String[] args) throws Exception {
|
|
char[][] g = {{'0','0','0','0','0','0','1'},{'0','0','0','0','1','1','1'},{'1','1','1','1','1','1','1'},{'0','0','0','1','1','1','1'}};
|
|
System.out.print(maximalRectangle(g));
|
|
}
|
|
|
|
public static int maximalRectangle(char[][] matrix) {
|
|
int x, y;
|
|
int i,j;
|
|
int row = matrix.length;
|
|
int col;
|
|
if (row == 0){
|
|
return 0;
|
|
}
|
|
else{
|
|
col = matrix[0].length;
|
|
}
|
|
int sum = 0;
|
|
for (x = 0; x < row; x++) {
|
|
for (y = 0; y < col; y++) {
|
|
if (matrix[x][y] == '1') {
|
|
i = x;
|
|
j = y;
|
|
int a = 1;
|
|
int b = 1;
|
|
int k;
|
|
int sum2 = 0;
|
|
while (i < row) {
|
|
if (matrix[i][y] == '1') { //竖着往下遍历
|
|
i++;
|
|
a = i - x;
|
|
j = y + 1;
|
|
int temp = j;
|
|
while (j < col) {
|
|
for (k = x; k < i; k++){
|
|
if (matrix[k][j] == '0'){ //遇到横的为零
|
|
temp = j;
|
|
b = temp - y;
|
|
j = col;
|
|
break;
|
|
}
|
|
else{
|
|
temp = j + 1;
|
|
}
|
|
}
|
|
j++;
|
|
}
|
|
b = temp - y;
|
|
if (a*b > sum2){
|
|
sum2 = a*b;
|
|
}
|
|
|
|
}
|
|
else{
|
|
break;
|
|
}
|
|
}
|
|
if (sum2 > sum){
|
|
sum = sum2;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return sum;
|
|
|
|
}
|
|
}
|