Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public int maximalRectangle(char[][] matrix) {
- int max = 0;
- for (int i = 0; i < matrix.length; i++) {
- for (int j = 0; j < matrix[0].length; j++) {
- int width = 0;
- int height = 0;
- for (int k = i; k < matrix.length && matrix[k][j] == '1'; k++) {
- width++;
- }
- for (int k = i; k < i + width; k++) {
- for (int l = j; l < matrix[0].length; l++) {
- if (matrix[k][l] == '0') {
- width = k - i;
- if (width * height > max) {
- max = width * height;
- }
- }
- }
- height++;
- }
- if (width * height > max) {
- max = width * height;
- }
- }
- }
- return max;
- }
- public static void main(String[] args) {
- Solution solution = new Solution();
- System.out.println(solution.maximalRectangle(new char[][]{{'1', '0', '1', '0', '0'}, {'1', '0', '1', '1', '1'}, {'1', '1', '1', '1', '1'}, {'1', '0', '0', '1', '0'}}));
- System.out.println(solution.maximalRectangle(new char[][]{{'1'}, {'0'}}));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement