Based on Largest Rectangle in Histogram
\nclass Solution {\n    public int largestRectangleArea(int[] heights) {\n    \n        \n    int[] left = new int[heights.length]; \n    int[] right = new int[
```\nclass Solution {\n    public int largestRectangleArea(int[] heights) {\n    \n        \n    int[] left = new int[heights.length]; \n    int[] right = new int[heights.length];\n    int[] width = new int[heights.length];\n    Stack<Integer> stack = new Stack();\n        \n        \n       //width --- left\n        for(int i=0;i<heights.length;i++){\n            \n            while(!stack.isEmpty() && heights[i]<=heights[stack.peek()]){\n                stack.pop();\n            }\n            \n            if(stack.isEmpty()){\n                left[i] = -1;\n            }else{\n                left[i] = stack.peek();\n            }\n            \n            stack.add(i);\n        }\n        stack.clear();\n        //width --- right\n        for(int i=heights.length-1;i>=0;i--){\n            \n            while(!stack.isEmpty() && heights[i]<=heights[stack.peek()]){\n                stack.pop();\n            }\n            \n            if(stack.isEmpty()){\n                right[i] = heights.length;\n            }else{\n                right[i] = stack.peek();\n            }\n            \n            stack.add(i);\n        }\n        \n        int area = 0;\n        \n         for(int i=0;i<heights.length;i++){\n            width[i] = right[i]-left[i]-1;\n            area = Math.max(heights[i]* width[i] ,area);\n         }\n        \n        return area;\n    }\n    public int maximalRectangle(char[][] matrix) {\n        if(matrix.length==0) return 0;\n        // for each cell with value=1, we look upward (north), the number of continuous \'1\' is the height of cell\n        int[] heights = new int[matrix[0].length];\n        int maxArea=-1;\n        for(int i=0; i<matrix.length; i++){\n            for(int j=0; j<matrix[0].length; j++){\n                if(matrix[i][j]==\'0\'){\n                    heights[j] = 0;\n                } else {\n                    heights[j] ++;\n                }\n            }            \n            int area = largestRectangleArea(heights);\n            maxArea = Math.max(maxArea, area);\n        }\n        return maxArea;\n    }\n}\n```
[]