@@ -0,0 +1,1538 @@
+// Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.%0A%0Apublic class Solution %7B%0A    public int maximalRectangle(char%5B%5D%5B%5D matrix) %7B%0A    %09int row = matrix.length;%0A    %09if(row == 0) return row;%0A    %09int col = matrix%5B0%5D.length;%0A%0A    %09// 2D matrix for storing the vertical/horizontal area acumulation. Here we%0A    %09// choose the horizaltol approach.%0A    %09int%5B%5D%5B%5D dp = new int%5Brow%5D%5Bcol%5D;%0A%0A    %09// initialize first col%0A    %09for(int i = 0; i %3C row; i++)%7B%0A    %09%09%09dp%5Bi%5D%5B0%5D = matrix%5Bi%5D%5B0%5D == '1'? 1 : 0;%0A%09%09%7D%0A%0A%09%09// fill the dp matrix, based on value at (i,j) in input matrix%0A    %09for(int i = 0; i %3C row; i++)%7B%0A    %09%09for(int j = 1; j %3C col; j++)%7B%0A    %09%09%09dp%5Bi%5D%5Bj%5D = matrix%5Bi%5D%5Bj%5D == '1'? dp%5Bi%5D%5Bj - 1%5D + 1 : 0;%0A    %09%09%7D%0A    %09%7D%0A%0A    %09int maxArea = 0;%0A%0A    %09// scan dp matrix again, for each element (i, j) check all valid %0A    %09// rectangles with (i, j) as right bottom corner. %0A    %09// How to identify valid: dp%5Bi%5D%5Bj%5D != 0%0A    %09for(int i = 0; i %3C row; i++)%7B%0A    %09%09for(int j = 0; j %3C col; j++)%7B%0A    %09%09%09int k = i;%0A    %09%09%09int width = Integer.MAX_VALUE;%0A%0A    %09%09%09// starting from kth line until ith line.%0A    %09%09%09while(k %3E= 0)%7B%0A    %09%09%09%09if(dp%5Bk%5D%5Bj%5D == 0)%7B%0A    %09%09%09%09%09break;%0A    %09%09%09%09%7D%0A%0A    %09%09%09%09// keep min value as width, width at (k,j) cound be larger than%0A    %09%09%09%09// element value at initial k=i index.%0A    %09%09%09%09width = Math.min(width, dp%5Bk%5D%5Bj%5D);%0A    %09%09%09%09int height = i - k + 1;%0A    %09%09%09%09maxArea = Math.max(maxArea, width * height);%0A    %09%09%09%09k--;%0A    %09%09%09%7D%0A    %09%09%7D%0A    %09%7D%0A%0A    %09return maxArea;%0A    %7D%0A%7D

add maximal rectangle solution