@@ -0,0 +1,1324 @@
+package problems;%0A%0Aimport java.util.Stack;%0A%0Apublic class MaximalRectangle %7B%0A    public int maximalRectangle(char%5B%5D%5B%5D matrix) %7B%0A        int m = matrix.length;%0A        if (m == 0)%0A            return 0;%0A        int n = matrix%5B0%5D.length;%0A        if (n == 0)%0A            return 0;%0A%0A        int%5B%5D H = new int%5Bn%5D;%0A        int max = 0;%0A        for (int i = 0; i %3C m; i++) %7B%0A            for (int j = 0; j %3C n; j++)%0A                H%5Bj%5D = (matrix%5Bi%5D%5Bj%5D == '0') ? 0 : H%5Bj%5D + 1;%0A%0A            max = Math.max(max, largestRectangleArea(H));%0A        %7D%0A        return max;%0A    %7D%0A%0A    int largestRectangleArea(int%5B%5D height) %7B%0A        int max = 0, i = 0;%0A        Stack%3CInteger%3E S = new Stack%3CInteger%3E();%0A        while (i %3C= height.length) %7B%0A            if (i == height.length && S.empty())%0A                i++;%0A            else if (i %3C height.length && (S.empty() %7C%7C height%5BS.peek()%5D %3C height%5Bi%5D)) %7B%0A                S.push(i);%0A                i++;%0A            %7D else %7B%0A                int t = S.pop();%0A                max = Math.max(max, height%5Bt%5D * (S.empty() ? i : i - S.peek() - 1));%0A            %7D%0A        %7D%0A        return max;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        MaximalRectangle mr = new MaximalRectangle();%0A%0A        char%5B%5D%5B%5D matrix = %7B %7B '0' %7D %7D;%0A%0A        System.out.println(mr.maximalRectangle(matrix));%0A    %7D%0A%7D%0A

Add Maximum Rectangle